简体   繁体   English

spring boot到Tomcat部署数据源问题

[英]spring boot to Tomcat deployment data source issue

I am building an application with Spring Boot, Neo4j and MongoDB. 我正在使用Spring Boot,Neo4j和MongoDB构建应用程序。 I have used @Configuration annotation to load database properties from application.properties like this: 我使用@Configuration批注从application.properties加载数据库属性,如下所示:

@Bean(name = "neoDriver")
@Profile("local")
public Driver getNeoDriver() {

    return GraphDatabase.driver(
      env.getProperty("datasource.neo4j.uri"),
      AuthTokens.basic(env.getProperty("datasource.neo4j.username"), env.getProperty("datasource.neo4j.password")),
      Config.build().toConfig());
}

The autowire code is autowire代码是

@Autowired
@Qualifier("neoDriver")
private Driver neoDriver;

when I run the application from IntelliJ, it runs fine; 当我从IntelliJ运行应用程序时,它运行良好; but when I try deploy the war file on Tomcat 8.5, it gives error. 但是当我尝试在Tomcat 8.5上部署war文件时,它会出错。

Field neoDriver in com......repository.PositionRepositoryImpl required a bean of type 'org.neo4j.driver.v1.Driver' that could not be found.

Caused by:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'Controller': Unsatisfied dependency expressed through field 'positionService'; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'Service': Unsatisfied dependency expressed through field 'positionRepository'; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'RepositoryImpl': Unsatisfied dependency expressed through field 'neoDriver'; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.neo4j.driver.v1.Driver' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=neoDriver)}

Please let me know what did I do wrong when deploying this on Tomcat. 请让我知道在Tomcat上部署它时我做错了什么。

I bet you're not setting spring.profiles.active to local in your Tomcat deployment. 我敢打赌你没有在你的Tomcat部署spring.profiles.active设置为local Because your bean is marked with the @Profile annotation, so it will only be created if that profile is active. 因为您的bean标有@Profile注释,所以只有在该配置文件处于活动状态时才会创建它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM