简体   繁体   中英

spring boot to Tomcat deployment data source issue

I am building an application with Spring Boot, Neo4j and MongoDB. I have used @Configuration annotation to load database properties from application.properties like this:

@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

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

when I run the application from IntelliJ, it runs fine; but when I try deploy the war file on Tomcat 8.5, it gives error.

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.

I bet you're not setting spring.profiles.active to local in your Tomcat deployment. Because your bean is marked with the @Profile annotation, so it will only be created if that profile is active.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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