maven - Running multiple Spring boot applications on same JVM -


i have multi-maven module spring boot project having following structure:

parent    |_ pom.xml    |_ webservices         |_ src/main/java              |_ webservices                   |_ webservicesconfig.java                   |_ webservicesstarter.java                   |_ globalpropertiesloader.java         |_ pom.xml    |_ backend         |_ src/main/java              |_ backend                   |_ backendstarter.java         |_ pom.xml    |_ commons         |_ src/main/java              |_ commons                   |_ globalpropertiesdao.java                   |_ globalpropertiesrepository.java                   |_ commonsconfig.java;         |_ pom.xml 

both webservices, , backend individual spring boot applications (they generate jar file use launching them) , depend on commons module. have included commons dependency in webservices , backend's pom.xml.

i have few questions starting applications.

  1. how start both backend , webservices in single jvm? (on same port)
  2. i want auto-wire globalpropertiesrepository (located within commons project) in backend , webservices project. how do this? can auto-wire across different modules? importing commons doesn't work. throws "no bean definition error". think because globalpropertiesrepository not launched spring container if import it.

============= update =============

adding configuration classes applications:

the commons application has empty configuration class since have repository class on there. below empty configuration class:

package commons;  import org.springframework.context.annotation.configuration;  @configuration public class commonsconfig {  } 

and globalpropertiesrepository:

package commons;  import org.springframework.data.repository.crudrepository; import org.springframework.stereotype.repository;  @repository public interface globalpropertiesrepository extends crudrepository<globalpropertiesdao, long>{ } 

below necessary classes in webservices application:

the starter class:

package webservices;  import org.springframework.beans.factory.config.beandefinition; import org.springframework.boot.springapplication; import org.springframework.boot.autoconfigure.springbootapplication; import org.springframework.data.jpa.repository.config.enablejparepositories; import org.springframework.context.annotation.classpathscanningcandidatecomponentprovider;  @springbootapplication @enablejparepositories @componentscan({"commons", "webservices"}) public class webservicesstarter {      public static void main(string[] args) throws exception {         springapplication.run(webservicesstarter.class, args);          classpathscanningcandidatecomponentprovider provider =                 new classpathscanningcandidatecomponentprovider(true);     }  } 

the configuration class:

package webservices;   import org.springframework.boot.context.embedded.filterregistrationbean; import org.springframework.context.annotation.bean; import org.springframework.context.annotation.configuration; import org.springframework.context.annotation.import;  import commons.commonsconfig;  @configuration @import(commonsconfig.class) public class webservicesconfig {      @autowired commonsconfig commonsconfig;     public webservicesconfig() {     } } 

and class i'm trying autowire repository:

package webservices;  import javax.annotation.postconstruct;  import org.springframework.beans.factory.annotation.autowired; import org.springframework.context.annotation.scope; import org.springframework.stereotype.component;  import commons.globalpropertiesdao; import commons.globalpropertiesrepository;  @component @scope("singleton") public class globalpropertiesloader {      @autowired     public globalpropertiesrepository globalpropertiesrepository;      private globalpropertiesdao globalproperties;      @postconstruct     public void init(){         globalproperties = globalpropertiesrepository.findone(1l);     }      public globalpropertiesdao getglobalproperties(){         return globalproperties;     }  } 

this error get:

caused by: org.springframework.beans.factory.beancreationexception: not autowire field: public commons.globalpropertiesrepository webservices.globalpropertiesloader.globalpropertiesrepository; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [commons.globalpropertiesrepository] found dependency: expected @ least 1 bean qualifies autowire candidate dependency. dependency annotations: {@org.springframework.beans.factory.annotation.autowired(required=true)}     @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject(autowiredannotationbeanpostprocessor.java:561)     @ org.springframework.beans.factory.annotation.injectionmetadata.inject(injectionmetadata.java:88)     @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:331) 

thanks.

i think know whats causing error.

in app starter class though have @componentscan({"commons", "webservices"}) reason @repository bean being ignored. think problem in class classpathbeandefinitionscanner. according documentation javadoc, state default scan components, including @repository. when identifies repository interfaces fails check in method iscandidatecomponent. (if in source)

so log when enable debug

2015-05-18 11:10:13.399 debug 67917 --- [ main] o.s.c.a.classpathbeandefinitionscanner : ignored because not concrete top-level class: file [****/jpa-test/dl/target/classes/commons/globalpropertiesrepository.class]

furthermore, because enablejparepositories scans package declared in , repository not being initialised.

if set baseclasspackage (type safe) property @enablejparepositories(basepackageclasses = globalpropertiesrepository.class) repository initialised. make sure add @entityscan(basepackageclasses = globalpropertiesdao.class)


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -