java - Spring loading beans which are based on application.properties from a sub-module -
i have 2 spring modules, parent module has child modules dependency. both projects has own spring annotated beans , beans created using @bean
. project child has child.properties
in ressources, file used set properties bean in child project. project parent has own parent.properties
used create beans in parent projects.
=> each 2 projects has serviceconfig
class annotated @configuration
use:
parent:
@bean public static propertyplaceholderconfigurer configuration(){ final propertyplaceholderconfigurer props=new propertyplaceholderconfigurer(); props.setlocations(new resource[]{new classpathresource("parent.properties")}); return props; }
child:
@bean public static propertyplaceholderconfigurer configuration(){ final propertyplaceholderconfigurer props=new propertyplaceholderconfigurer(); props.setlocations(new resource[]{new classpathresource("child.properties")}); return props; }
now question is: need autowire bean child parent project , when run parent project (which has child project dependency in pom.xml
), child bean autowired couldn't constructed because child.properties
aren't loaded. , when debuged see spring enter in propertyplaceholderconfigurer
bean parent not child. , when remove propertyplaceholderconfigurer
parent, spring loads propertyplaceholderconfigurer
bean child project.
i can resolve issue placing child.properties
file in parent project don't solution, keep each configuration project.
since have same bean name both propertyplaceholderconfigurer beans, child bean overridden parent 1 (if you'll closely in log, you'll see stated there) try giving them different names
Comments
Post a Comment