我有一个麻烦与Springfox昂首阔步2为我的API留档。它无法识别我的Rest存储库(JpaRepository/PagingAndSortingRepository)。
import org.springframework.data.jpa.repository.JpaRepository;
import com.aegon.dop.model.Book;
public interface BookRepository extends JpaRepository<Book, Long> {
}
甚至我也尝试添加下面这样的招摇注释,但没有成功
@Api(tags = "books")
@RepositoryRestResource(collectionResourceRel = "books", path = "books")
public interface BookRepository extends JpaRepository<Book, String> {
@ApiOperation("Find all books by book name")
Dopadviseur findByBookName(@Param("bookName") @RequestParam @ApiParam(value = "bookName") String bookName);
}
而HAL浏览器可以识别我的Rest存储库。有人能帮我吗?这是我对pom的依赖,
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Demo</name>
<description>Demo application</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-boot-admin.version>2.0.1</spring-boot-admin.version>
<spring-fox-version>2.9.2</spring-fox-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0</version>
</dependency>
<!-- Swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${spring-fox-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-data-rest</artifactId>
<version>${spring-fox-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${spring-fox-version}</version>
</dependency>
<!-- Soap Webservices -->
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-dependencies</artifactId>
<version>${spring-boot-admin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
</project>
这是我的靴子课,
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;
import springfox.documentation.spring.data.rest.configuration.SpringDataRestConfiguration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication
@EnableSwagger2
@Import({ SpringDataRestConfiguration.class })
public class DopApplication {
public static void main(String[] args) {
SpringApplication.run(DopApplication.class, args);
}
}
当我添加@Import({SpringDataRestConfiguration.class})
时,在应用程序启动时出现以下错误
Caused by: java.lang.NoSuchMethodError: org.springframework.data.repository.support.Repositories.getRepositoryInformationFor(Ljava/lang/Class;)Lorg/springframework/data/repository/core/RepositoryInformation;
at springfox.documentation.spring.data.rest.EntityServicesProvider.requestHandlers(EntityServicesProvider.java:81) ~[springfox-data-rest-2.9.2.jar:null]
at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper$2.apply(DocumentationPluginsBootstrapper.java:138) ~[springfox-spring-web-2.9.2.jar:null]
at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper$2.apply(DocumentationPluginsBootstrapper.java:135) ~[springfox-spring-web-2.9.2.jar:null]
at com.google.common.collect.Iterators$7.transform(Iterators.java:750) ~[guava-20.0.jar:na]
我认为您需要在代码中包含以下内容:
@导入({springfox.documentation.spring.data.rest.configuration.SpringDataRestConfiguration.class})
看看下面讨论你问题的帖子:
https://github.com/springfox/springfox/issues/699#issuecomment-270052170
@springbootplication@EnableSwagger2@Import({springfox.documentation.spring.data.rest.configuration.SpringDataRestConfiguration.class})公共类Servletilizer扩展了SpringBootServletilizer{
我认为你应该升级到:
Spring Fox 2.9.0:https://github.com/springfox/springfox/issues/2372他们提到了一个与您非常相似的问题,该版本解决了这个问题。
https://github.com/springfox/springfox/issues/2272
我如何访问生成的swagger-ui.html?或者index.html我似乎在我的项目中找不到这个文件。啊啊!
字符串不能解析为类型
我按照这个教程https://spring framework . guru/spring-boot-restful-API-documentation-with-swagger-2/生成了一个swagger文档。它可以工作,但是当我试图在bean中添加一些验证时,我在文档中找不到信息: 带有验证注释的我的实体: 这里,https://github.com/springfox/springfox/
几天前,我在JavaEE 7中启动了一个REST API,我用三个方法实现了一个类,并在项目中成功地实现了Swagger和Swagger-UI,它显示了我在生成的JSON中成功实现的三个endpoint。 但是,我迁移到JavaEE8,在此更改之后,Swagger检测到几个未知endpoint,比如“默认”endpoint(此捕获只显示了其中的一部分): 通过研究,我发现这些endpoint可能属
问题内容: 我有一个名为EmployeeDepartment的实体,如下所示 我有一个如下定义的Spring Data Repository 此外,我注册了一个转换器,以将String转换为EmployeeDepartmentPK。 现在,对于一个由ID employeeID =“ abc123”和departmentCode =“ JBG”限定的实体,我希望在调用SDR接口时使用的ID为abc1
我有一个与cassandra连接的springboot应用程序。我试图在地图中创建地图,但遇到以下异常。在我看来,即使我使用了冻结值,它仍在发送cal,但没有关键字冻结 错误 代码 马文