java - Spring initialization not working when the library is added as a dependency -
i have library exercises spring , getting initialized when run in project. when start other project , add library dependency, getting initialization failure. here code:
public class cbrepofactory implements irepofactory { private useractivityrepositoryservice useractivityrepositoryservice; private iteminformationrepositoryservice iteminformationrepositoryservice; public cbrepofactory() { annotationconfigapplicationcontext ctx = new annotationconfigapplicationcontext(); ctx.register(config.class); ctx.scan("com.example.db.app"); ctx.refresh(); useractivityrepositoryservice = ctx.getbean(useractivityrepositoryservice.class); iteminformationrepositoryservice = ctx.getbean(iteminformationrepositoryservice.class); // ctx.close(); } @override public irepoclient<useractivity> getuseractivityrepositoryservice() { // todo auto-generated method stub return this.useractivityrepositoryservice; } @override public irepoclient<iteminformation> getiteminformationrepositoryservice() { // todo auto-generated method stub return this.iteminformationrepositoryservice; } } here exception getting project when added dependency.
[main] info org.springframework.context.annotation.annotationconfigapplicationcontext - refreshing org.springframework.context.annotation.annotationconfigapplicationcontext@3d71d552: startup date [fri aug 18 14:05:41 pdt 2017]; root of context hierarchy exception in thread "main" java.lang.noclassdeffounderror: org/springframework/core/io/support/propertysourcefactory @ org.springframework.context.annotation.configurationclasspostprocessor.processconfigbeandefinitions(configurationclasspostprocessor.java:301) @ org.springframework.context.annotation.configurationclasspostprocessor.postprocessbeandefinitionregistry(configurationclasspostprocessor.java:228) @ org.springframework.context.support.postprocessorregistrationdelegate.invokebeandefinitionregistrypostprocessors(postprocessorregistrationdelegate.java:270) @ org.springframework.context.support.postprocessorregistrationdelegate.invokebeanfactorypostprocessors(postprocessorregistrationdelegate.java:93) @ org.springframework.context.support.abstractapplicationcontext.invokebeanfactorypostprocessors(abstractapplicationcontext.java:687) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:525) @ com.ebay.db.app.clientimpl.cbrepofactory.<init>(cbrepofactory.java:23) @ com.ebay.db.app.clientimpl.repofactorybuilder.createfactory(repofactorybuilder.java:11) @ testdbclient.testprogram.main(testprogram.java:15) caused by: java.lang.classnotfoundexception: org.springframework.core.io.support.propertysourcefactory @ java.net.urlclassloader.findclass(unknown source) @ java.lang.classloader.loadclass(unknown source) @ sun.misc.launcher$appclassloader.loadclass(unknown source) @ java.lang.classloader.loadclass(unknown source) ... 9 more can me this.
the first 5 lines showing info need , place find answer:
slf4j: class path contains multiple slf4j bindings. slf4j: found binding in [jar:file:/c:/users/sukrishna/.m2/test2/org/slf4j/slf4j-simple/1.7.5/slf4j-simple-1.7.5.jar!/org/slf4j/impl/staticloggerbinder.class] slf4j: found binding in [jar:file:/c:/users/sukrishna/.m2/test2/org/slf4j/slf4j-log4j12/1.7.10/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/staticloggerbinder.class] slf4j: see http://www.slf4j.org/codes.html#multiple_bindings explanation. slf4j: actual binding of type [org.slf4j.impl.simpleloggerfactory] line 1 states actual problem. multiple slf4j bindings. means have more logger versions/implementations trying same thing, raises exception.
lines 2 , 3 show conflict occured
line 4 tells more info error. , if do, see suggest here. if have multiple implementations in pom (i haven't seen it, though), can exclude 1 not on line 5, so:
<exclusions> <exclusion> <groupid>org.slf4j</groupid> <artifactid>slf4j-log4j12</artifactid> </exclusion> <exclusion> <groupid>log4j</groupid> <artifactid>log4j</artifactid> </exclusion> </exclusions> if doesn't work: try purging local .m2 repository, maybe several loggers cached there. can with:
mvn dependency:purge-local-repository that 1 works fine me, however, if still runs binding issues, purge repo bellow command, remain empty , download dependencies again (after purging):
mvn dependency:purge-local-repository -dacttransitively=false -dreresolve=false i don't know why happened, haven't posted pom avoid such issues using slf4j comes spring-boot no dependencies needed. can instantiate so:
private final logger logger = loggerfactory.getlogger(this.getclass()); hope helps
Comments
Post a Comment