0

I have two spring boot applications one is getting added as a dependency to the other. Dependent child project was able to run on it own. Created the classifier to be able to access.

@SpringBootApplication(scanBasePackages = "com.project.subproject")
public class Application {
    public static void main(String args[]) {
        new SpringApplicationBuilder(Application.class)
                .properties("spring.config.name=application-subproject-default").run(args);
    }
}

This application works perfectly fine with its own datasource, controllers & advice

Child project is added :

<dependency>
   <groupId>com.project.subproject</groupId>
   <artifactId>subproject</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <exclusions>
      <exclusion>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-undertow</artifactId>
      </exclusion>
    </exclusions>

Parent project Spring boot application :

@SpringBootApplication(scanBasePackages = "com.project")
public class MainApplication {
    public static void main(String args[]) {
        new SpringApplicationBuilder(MainApplication.class).properties("spring.config.name=application-parent-default").run(args);
    }
}

application-parent-default.yml
spring:
  application:
    name: parent

Subproject is getting scanned from the parent, but the datasource initialization is failing.

    Unsatisfied dependency expressed through field 'jdbcTemplate'; 
    nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; 
    nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; 
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; 
nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: 
Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. 
If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active)

Looks like the @SpringBootApplication in the child project is not getting invoked to initialize the yml file.

Any insights will be helpful

kiran reddy
  • 135
  • 17
  • Just a guess but what happens if you duplicate the content of the child `application.properties` into the parent? – Rafa Sep 18 '17 at 02:45
  • I am actually trying to keep the properties at the subproject level. used spring.config.name to the same effect to load app specific properties – kiran reddy Sep 18 '17 at 05:39
  • Its not actually a duplicate, the way multiple spring.config.name is used is not initializing the child properties, M. Denium reference to the duplicate is just the basic problem of adding a child project, I kind of the found a solution to use spring.config.location in the parent project to refer to the child config properties. According to the documentation spring.config.name and spring.config.location are initialized only once and needs to be set as environment variables. Keeping the question open if there is a better solution. – kiran reddy Sep 18 '17 at 16:14

0 Answers0