spring mvc - How to avoid error with Injection of autowired dependencies in Java based configuration? -


i use java based configuration. when have had 1 userrepository bean, working fine. when added 1 implementation of userrepository, got error

org.springframework.beans.factory.beancreationexception: error creating bean name 'answerservice': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: public com.springapp.mvc.service.newuserservice com.springapp.mvc.service.answerservice.userservice; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'newuserservice': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: public com.springapp.mvc.repository.userrepository com.springapp.mvc.service.newuserservice.userrepository; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no unique bean of type [com.springapp.mvc.repository.userrepository] defined: expected single matching bean found 2: [jpauserrepository, jsonuserrepository]

here configuration:

@enablewebmvc @configuration @componentscan("com.springapp.mvc") @propertysource("classpath:names.properties") public class webmvcconfig extends webmvcconfigureradapter {      @bean     public internalresourceviewresolver setupviewresolver() {         internalresourceviewresolver resolver = new internalresourceviewresolver();         resolver.setprefix("/web-inf/pages/");         resolver.setsuffix(".jsp");         return resolver;     }      @override     public void addresourcehandlers(resourcehandlerregistry registry) {         registry.addresourcehandler("/resources/**").addresourcelocations("/web-inf/resources/");     } } 

and service using 1 of userservice implementation:

@service public class newuserservice {      @autowired     @qualifier("jsonrepo")     public userrepository userrepository;      // methods ommited } 

i tried add @qualifier annotation userrepository userrepository , specific implementation:

@repository("jsonrepo") public class jsonuserrepository implements userrepository {...} 

but doesn't work.

how can fix problem?

try this:

@repository @qualifier("jsonrepo") public class jsonuserrepository implements userrepository {...} 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -