java - Cant inject autowire bean into my class -


i have spring bean defined, when add last 4 lines autowiring restclient rest bean, getting error (if remove last 3 lines, spring container loads fine):

@component public class timeseriesserviceimpl {      private static logger log = logger.getlogger(timeseriesserviceimpl.class);      @postconstruct     public void init() {         system.out.println("myservice init method called");     }      @predestroy     public void destory(){         system.out.println("myservice destroy method called");     }      @autowired     @qualifier("restclient")       public restclient rest ; 

error:

2016-02-07 18:46:41.609  warn 11084 --- [main] ationconfigembeddedwebapplicationcontext : exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.beancreationexception: error creating bean name 'timeseriesserviceimpl': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: public com.ge.predix.solsvc.restclient.impl.restclient com.tcs.timeseries.service.timeseriesserviceimpl.rest; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [com.ge.predix.solsvc.restclient.impl.restclient] 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.qualifier(value=restclient)} 2016-02-07 18:46:41.612  info 11084 --- [main] o.apache.catalina.core.standardservice   : stopping service tomcat 2016-02-07 18:46:41.623 error 11084 --- [main] o.s.boot.springapplication               : application startup failed 

i using maven spring boot application

@springbootapplication @enableautoconfiguration @componentscan(basepackages={"com.tcs.timeseries.*","com.ge.predix.solsvc.restclient.config.*", "com.ge.predix.solsvc.restclient.impl.*"}) @propertysource("classpath:application-default.properties") @contextconfiguration(locations = {          "classpath*:meta-inf/spring/application-context.xml"                  }) public class timeseriesclientapplication {      private static final logger log = loggerfactory.getlogger(timeseriesclientapplication.class);      public static void main(string[] args) {         //springapplication.run(timeseriesclientapplication.class, args);              springapplication springapplication = new springapplication(timeseriesclientapplication.class);             applicationcontext ctx = springapplication.run(args);              log.info("let's inspect beans provided spring boot:");             string[] beannames = ctx.getbeandefinitionnames();               arrays.sort(beannames);             (string beanname : beannames)             {                 log.info(beanname);             }      } 

details of restclientimpl bean:

@component(value = "restclient") public class restclientimpl         implements restclient, applicationcontextaware {      private static logger                  log                  = loggerfactory.getlogger(restclientimpl.class);      /**      *       */     @autowired     protected ioauthrestconfig             restconfig;      private javax.net.ssl.sslsocketfactory sslsocketfactory;      private sslcontext                     sslcontext;      private applicationcontext             applicationcontext;      static private final objectmapper      mapper               = new objectmapper()                                                                         .configure(                                                                                 deserializationconfig.feature.fail_on_unknown_properties,                                                                                 false).setserializationinclusion(                                                                                 jsonserialize.inclusion.non_null);     /**      *       */     static final string                    default_content_type = "application/json";                             //$non-nls-1$       private poolinghttpclientconnectionmanager poolmanager;      /**      *       */     public restclientimpl()     {         super();     }      @postconstruct     private void init()     {         setupsecurecontext(this.restconfig.getoauthcertlocation(), this.restconfig.getoauthcertpassword());         poolmanager = new poolinghttpclientconnectionmanager();         if(poolmanager !=null ) {             poolmanager.setmaxtotal(this.restconfig.getoauthpoolmaxsize());             poolmanager.setdefaultmaxperroute(this.restconfig.getoauthpoolmaxsize());         }    } 

do not include * while specifying basepackages attribute in @componentscan annotation.

so replace same code below -

@componentscan(basepackages={"com.tcs.timeseries","com.ge.predix.solsvc.restclient.config", "com.ge.predix.solsvc.restclient.impl"}) 

this scan packages , sub-packages.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -