【问题标题】:spring boot to Tomcat deployment data source issuespring boot to Tomcat部署数据源问题
【发布时间】:2023-03-14 03:08:01
【问题描述】:

我正在使用 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());
}

自动装配代码是

@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 上部署时我做错了什么。

【问题讨论】:

  • 假设他们是 github 中关于 spring boot 和 Neo4J 的一个很好的例子。参考这个post

标签: spring tomcat


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-02-15
    • 1970-01-01
    • 2016-03-28
    • 2019-04-30
    • 1970-01-01
    • 2019-05-05
    • 1970-01-01
    • 2014-09-04
    • 2015-03-10
    相关资源
    最近更新 更多