0

背景

我有一个带有 spring data neo4j 的应用程序,我从 4.1.3 切换到 5.0.0。

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

我当前版本的 spring boot 是

<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 以开始像在 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.
4

1 回答 1

1

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

@EnableNeo4jRepositories("myproject.repository")

更新 :

我刚刚看到您使用的是 Spring Boot 1.4。SDN 5 仅与 Spring Boot 2.0 兼容。详细信息在兼容性表中

于 2017-10-05T07:06:36.630 回答