当我从spring数据neo4j 4.1.3切换到5.0.0时,SpringBoot现在失败了

时间:2017-10-04 19:28:03

标签: spring spring-data-neo4j-5

背景

我有一个弹簧数据neo4j的应用程序,我从4.1.3切换到5.0.0。

我相信我已经做了所有必要的更改来转换我的代码,但我仍然会遇到错误。

我目前的弹簧靴版本是

<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"})添加到我的Application类,则错误消失,但是spring boot无法加载任何控制器,因此我的Swagger没有显示API,也没有运行控制器。这不是解决方案。 @SpringBootApplication应该照顾这一切。

问题

如何重新配置​​spring boot以开始像弹簧数据neo4j的4.1.3版一样工作?

UPDATE 1 ATTEMPT#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")并绕过Update 1中的错误,我尝试了:

mvn clean install spring-boot:repackage

它给了Build Success,但同样的错误仍然存​​在:

[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.

1 个答案:

答案 0 :(得分:1)

尝试在配置类上添加此注释:

@EnableNeo4jRepositories("myproject.repository")

更新:

我刚刚看到你在Spring boot 1.4上。 SDN 5仅与Spring Boot 2.0兼容。 详细信息位于compatibility table