繁体   English   中英

spring boot到Tomcat部署数据源问题

[英]spring boot to Tomcat deployment data source issue

我正在使用Spring Boot,Neo4j和MongoDB构建应用程序。 我使用@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());
}

autowire代码是

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

当我从IntelliJ运行应用程序时,它运行良好; 但是当我尝试在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)}

请让我知道在Tomcat上部署它时我做错了什么。

我敢打赌你没有在你的Tomcat部署spring.profiles.active设置为local 因为您的bean标有@Profile注释,所以只有在该配置文件处于活动状态时才会创建它。

暂无
暂无

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

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