当我从 spring 数据 neo4j 4.1.3 切换到 5.0.0 时,SpringBoot 现在失败
SpringBoot Fails now when I switch from spring data neo4j 4.1.3 to 5.0.0
背景
我有一个带有 spring 数据 neo4j 的应用程序,我从 4.1.3 切换到 5.0.0。
我相信我已经进行了所有必要的更改来转换我的代码,但我仍然遇到错误。
我当前的 spring 引导版本是
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>
问题
当我运行: mvn spring-boot:run
在命令行中,
我收到一个错误:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field actionRepository in myproject.service.ActionServiceImpl required a bean of type 'myproject.repository.ActionRepository' that could not be found.
Action:
Consider defining a bean of type 'myproject.repository.ActionRepository' in your configuration
我的myproject.Application.java目前
@SpringBootApplication
@EnableTransactionManagement
@EnableSwagger2
@EntityScan(basePackages = "myproject.domain")
public class Application {
public static void main(String[] args) {
new SpringApplication(Application.class).run(args);
}
@Bean
public Docket Api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.pathMapping("/")
.apiInfo(apiInfo());
}
private springfox.documentation.service.ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Service API")
}
}
并且这没有找到我的任何控制器,例如 myproject.controller.ActionController.java 其中包含
...
@RestController
@Api(value = "Action", description = "Actions Management API")
@RequestMapping(value = "/api/action")
public class ActionController extends Controller<Action> {
...
尝试 #1
如果我将注解 @ComponentScan({"myproject.request"})
添加到我的应用程序 class,错误就会消失,但是 spring 启动无法加载任何控制器,因此我的 Swagger 没有显示任何 API,也没有控制器 运行。这不是解决方案。 @SpringBootApplication
应该处理所有这些。
问题
如何重新配置 spring 引导以像在 spring data neo4j 4.1.3 版本中那样开始工作?
更新 1 次尝试 #2
我尝试将此注释添加到我的 class Application
@EnableNeo4jRepositories("myproject.repository")
并且错误变得不那么干净了:
...
2017-10-05 13:19:46.992 ERROR 561 --- [ main] o.s.boot.SpringApplication : Application startup failed
java.lang.NoSuchMethodError: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional;
at org.springframework.data.neo4j.repository.config.Neo4jRepositoryConfigurationExtension.postProcess(Neo4jRepositoryConfigurationExtension.java:110) ~[spring-data-neo4j-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn(RepositoryConfigurationDelegate.java:130) ~[spring-data-commons-1.12.0.RELEASE.jar:na]
at org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport.registerBeanDefinitions(RepositoryBeanDefinitionRegistrarSupport.java:83) ~[spring-data-commons-1.12.0.RELEASE.jar:na]
...
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.1.RELEASE:run (default-cli) on project myproject: An exception occurred while running. null: InvocationTargetException: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional; -> [Help 1]
[ERROR]
...
更新 2
为了尝试使用 @EnableNeo4jRepositories("myproject.repository")
并绕过更新 1 中的错误,我尝试了:
mvn clean install spring-boot:repackage
它给出了构建成功,但同样的错误仍然存在:
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.1.RELEASE:run (default-cli) on project myproject: An exception occurred while running. null: InvocationTargetException: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional; -
更新 3
我有新的注释并更改了我的 pom:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.12.0.RELEASE</version>
</dependency>
至
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
现在 mvn spring-boot:run
报错:
***************************
APPLICATION FAILED TO START
***************************
Description:
A component required a bean named 'getSessionFactory' that could not be found.
Action:
Consider defining a bean named 'getSessionFactory' in your configuration.
尝试在您的配置中添加此注释 class :
@EnableNeo4jRepositories("myproject.repository")
更新:
我刚刚看到您使用的是 Spring boot 1.4。 SDN 5 仅与 Spring Boot 2.0 兼容。
详情在 compatibility table.
背景
我有一个带有 spring 数据 neo4j 的应用程序,我从 4.1.3 切换到 5.0.0。
我相信我已经进行了所有必要的更改来转换我的代码,但我仍然遇到错误。
我当前的 spring 引导版本是
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>
问题
当我运行: mvn spring-boot:run
在命令行中,
我收到一个错误:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field actionRepository in myproject.service.ActionServiceImpl required a bean of type 'myproject.repository.ActionRepository' that could not be found.
Action:
Consider defining a bean of type 'myproject.repository.ActionRepository' in your configuration
我的myproject.Application.java目前
@SpringBootApplication
@EnableTransactionManagement
@EnableSwagger2
@EntityScan(basePackages = "myproject.domain")
public class Application {
public static void main(String[] args) {
new SpringApplication(Application.class).run(args);
}
@Bean
public Docket Api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.pathMapping("/")
.apiInfo(apiInfo());
}
private springfox.documentation.service.ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Service API")
}
}
并且这没有找到我的任何控制器,例如 myproject.controller.ActionController.java 其中包含
...
@RestController
@Api(value = "Action", description = "Actions Management API")
@RequestMapping(value = "/api/action")
public class ActionController extends Controller<Action> {
...
尝试 #1
如果我将注解 @ComponentScan({"myproject.request"})
添加到我的应用程序 class,错误就会消失,但是 spring 启动无法加载任何控制器,因此我的 Swagger 没有显示任何 API,也没有控制器 运行。这不是解决方案。 @SpringBootApplication
应该处理所有这些。
问题
如何重新配置 spring 引导以像在 spring data neo4j 4.1.3 版本中那样开始工作?
更新 1 次尝试 #2
我尝试将此注释添加到我的 class Application
@EnableNeo4jRepositories("myproject.repository")
并且错误变得不那么干净了:
...
2017-10-05 13:19:46.992 ERROR 561 --- [ main] o.s.boot.SpringApplication : Application startup failed
java.lang.NoSuchMethodError: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional;
at org.springframework.data.neo4j.repository.config.Neo4jRepositoryConfigurationExtension.postProcess(Neo4jRepositoryConfigurationExtension.java:110) ~[spring-data-neo4j-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn(RepositoryConfigurationDelegate.java:130) ~[spring-data-commons-1.12.0.RELEASE.jar:na]
at org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport.registerBeanDefinitions(RepositoryBeanDefinitionRegistrarSupport.java:83) ~[spring-data-commons-1.12.0.RELEASE.jar:na]
...
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.1.RELEASE:run (default-cli) on project myproject: An exception occurred while running. null: InvocationTargetException: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional; -> [Help 1]
[ERROR]
...
更新 2
为了尝试使用 @EnableNeo4jRepositories("myproject.repository")
并绕过更新 1 中的错误,我尝试了:
mvn clean install spring-boot:repackage
它给出了构建成功,但同样的错误仍然存在:
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.1.RELEASE:run (default-cli) on project myproject: An exception occurred while running. null: InvocationTargetException: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional; -
更新 3
我有新的注释并更改了我的 pom:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.12.0.RELEASE</version>
</dependency>
至
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
现在 mvn spring-boot:run
报错:
***************************
APPLICATION FAILED TO START
***************************
Description:
A component required a bean named 'getSessionFactory' that could not be found.
Action:
Consider defining a bean named 'getSessionFactory' in your configuration.
尝试在您的配置中添加此注释 class :
@EnableNeo4jRepositories("myproject.repository")
更新:
我刚刚看到您使用的是 Spring boot 1.4。 SDN 5 仅与 Spring Boot 2.0 兼容。 详情在 compatibility table.