java - BeanNameAutoProxyCreator setBeanNames regular expression not working? -
this beannameautoproxycreator
:
@bean public beannameautoproxycreator beannameautoproxycreator() { beannameautoproxycreator beannameautoproxycreator = new beannameautoproxycreator(); beannameautoproxycreator.setbeannames("*service"); // if put "*service" instead, exception. beannameautoproxycreator.setinterceptornames("loggingadvice", "debuginterceptor"); return beannameautoproxycreator; } @bean public loggingadvice loggingadvice() { return new loggingadvice(); } @bean public debuginterceptor debuginterceptor() { return new debuginterceptor(); }
and clientservice bean:
@bean @scope(beandefinition.scope_prototype) public clientservice clientservice() { return new clientserviceimpl(this.clientdao); }
so, don't know why, when call setbeannames("*service")
not setting interceptors. if put "*service" exception:
org.springframework.beans.factory.beancreationexception: error creating bean name 'requestmappinghandleradapter' defined in class path resource [org/springframework/boot/autoconfigure/web/webmvcautoconfiguration$enablewebmvcconfiguration.class]: bean instantiation via factory method failed; nested exception org.springframework.beans.beaninstantiationexception: failed instantiate [org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter]: factory method 'requestmappinghandleradapter' threw exception; nested exception java.lang.classcastexception: com.sun.proxy.$proxy68 cannot cast org.springframework.format.support.formattingconversionservice @ org.springframework.beans.factory.support.constructorresolver.instantiateusingfactorymethod(constructorresolver.java:599) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.instantiateusingfactorymethod(abstractautowirecapablebeanfactory.java:1111) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbeaninstance(abstractautowirecapablebeanfactory.java:1006) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:504) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:476) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:303) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:299) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:194) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:755) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:757) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:480) @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.refresh(embeddedwebapplicationcontext.java:118) @ org.springframework.boot.springapplication.refresh(springapplication.java:686) @ org.springframework.boot.springapplication.run(springapplication.java:320) @ org.springframework.boot.springapplication.run(springapplication.java:957) @ org.springframework.boot.springapplication.run(springapplication.java:946) @ com.example.movies.service.application.main(application.java:9) caused by: org.springframework.beans.beaninstantiationexception: failed instantiate [org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter]: factory method 'requestmappinghandleradapter' threw exception; nested exception java.lang.classcastexception: com.sun.proxy.$proxy68 cannot cast org.springframework.format.support.formattingconversionservice @ org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy.java:189) @ org.springframework.beans.factory.support.constructorresolver.instantiateusingfactorymethod(constructorresolver.java:588) ... 17 common frames omitted caused by: java.lang.classcastexception: com.sun.proxy.$proxy68 cannot cast org.springframework.format.support.formattingconversionservice @ org.springframework.boot.autoconfigure.web.webmvcautoconfiguration$enablewebmvcconfiguration$$enhancerbyspringcglib$$f6264082.mvcconversionservice(<generated>) @ org.springframework.web.servlet.config.annotation.webmvcconfigurationsupport.getconfigurablewebbindinginitializer(webmvcconfigurationsupport.java:492) @ org.springframework.web.servlet.config.annotation.webmvcconfigurationsupport.requestmappinghandleradapter(webmvcconfigurationsupport.java:461) @ org.springframework.boot.autoconfigure.web.webmvcautoconfiguration$enablewebmvcconfiguration.requestmappinghandleradapter(webmvcautoconfiguration.java:343) @ org.springframework.boot.autoconfigure.web.webmvcautoconfiguration$enablewebmvcconfiguration$$enhancerbyspringcglib$$f6264082.cglib$requestmappinghandleradapter$1(<generated>) @ org.springframework.boot.autoconfigure.web.webmvcautoconfiguration$enablewebmvcconfiguration$$enhancerbyspringcglib$$f6264082$$fastclassbyspringcglib$$37e805df.invoke(<generated>) @ org.springframework.cglib.proxy.methodproxy.invokesuper(methodproxy.java:228) @ org.springframework.context.annotation.configurationclassenhancer$beanmethodinterceptor.intercept(configurationclassenhancer.java:309) @ org.springframework.boot.autoconfigure.web.webmvcautoconfiguration$enablewebmvcconfiguration$$enhancerbyspringcglib$$f6264082.requestmappinghandleradapter(<generated>) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy.java:162) ... 18 common frames omitted
and if put "clientservice" works fine not want. want beans ends "service" intercepted. reason, "*service" not working.
you'd have set
beannameautoproxycreator.setproxytargetclass(true);
so spring uses cglib proxy instances. otherwise, uses jdk proxies support interfaces.
note you're proxying (knowingly or unknowingly) beans may registered web mvc configuration. these might not support proxying (final
classes example).
Comments
Post a Comment