现在,当我从弹簧数据NEO4J 4.1.3转换为5.0.0时,Springboot失败了



背景

我有一个带有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.actorcontroller.java,其中包含

...
@RestController
@Api(value = "Action", description = "Actions Management API")
@RequestMapping(value = "/api/action")
public class ActionController extends Controller<Action> {
...

尝试#1

如果我将注释@ComponentScan({"myproject.request"})添加到我的应用程序类中,则错误会消失,但是Spring Boot无法加载任何控制器,因此我的Swagger没有显示API,也没有运行控制器。这不是解决方案。@SpringBootApplication应该照顾所有这些。

问题

如何重新覆盖春季启动以开始工作,就像在弹簧数据的4.1.3版中一样,neo4j?

更新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安装弹簧靴:重新包装

它给出了成功的成功,但同样的错误仍然存在:

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

to

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

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

@EnableNeo4jRepositories("myproject.repository")

更新:

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

相关内容

  • 没有找到相关文章

最新更新