[英]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.