:
note that the following two errors may be caused by not properly configuring the values of proxy-target-class:
error 1 : No qualifying bean of type ‘com. PJH. Service. Imp. ServiceImp’ available
error strong> : The Exception in the thread “main” Java. Lang. ClassCastException: com. Sun. Proxy. $Proxy8 always be cast to XXX — — — — — — — dynamic proxy (proxy – target – the meaning of the class attribute) p>
this means roughly strong> : no type is’ com. PJH. Service. Imp. ServiceImp “qualified bean available p> proxy: this is caused by not configuring proxy-target-class I use this code for: strong>
H2> why?
proxy-target-class has two values: true/false
determines whether a proxy is created based on the interface or based on the class .
if the proxy-target-class attribute value is set to true, then the class-based proxy will come into play (in which case the cglib library is required). If the proxy-target-class attribute value is set to false or this property is omitted, the standard JDK interface-based proxy will come into effect.
statement strong> : serviceImp is to implement the service interface is the parent of the
serviceImp bean1 = (serviceImp) classPathXmlApplicationContext. GetBean (serviceImp. Class);
and serviceImp is a class, not an interface
, but I did not configure proxy-target-class attribute when I was woven in, the default is proxy-target-class=false, this is based on the interface proxy, so the error is
, which is the content of the error : No type is’ com. PJH. Service. Imp. ServiceImp “qualified bean available p> <aop:config>
<aop:pointcut id="txPointcut" expression="execution(* com.pjh.service.Imp.serviceImp.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
</aop:config>
solution
when I change the value of the code’s proxy-target-class to true, I will not report an error, that is, I will change the class-based proxy
<aop:config proxy-target-class="true">
<aop:pointcut id="txPointcut" expression="execution(* com.pjh.service.Imp.serviceImp.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
</aop:config>
To change the passed parameters to interface, there is no need to add proxy-target-class, because the default is false, which is based on the interface proxy
declaration : serivce is the parent class of serviceImp is an interface
service bean1 =(service) classPathXmlApplicationContext.getBean(service.class);
above is the error encountered today and its solution, if there is help, please pay attention to thumb up, this is the greatest support for bloggers, I will often update my study notes and problems encountered
Read More:
- Method threw ‘java.lang.NullPointerException‘ exception. Cannot evaluate com.sun.proxy.xxx
- [Solved] Flowable Start Error: ClassCastException: java.time.LocalDateTime cannot be cast to java.lang.String
- Realize the simplest recursive call, simulate exception in thread “main” java.lang.stackoverflowerror exception
- How to Fix Exception in thread “main“ com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications
- Error:Unknown host ‘maven.aliyun.com‘. You may need to adjust the proxy settings in Gradle.
- Google set proxy, ERR_PROXY_CONNECTION_FAILED
- Proxy error:could not proxy request
- When configuring the proxy with Vue, the front-end requests the server-side error 504; the Vue console reports the error occurred while trying to proxy request
- [Solved] Mac ES Startup Error: Exception in thread “main“ java.nio.file.NotDirectoryException
- objs/addon/ngx_http_proxy_connect_module-master/ngx_http_proxy_connect_module.o] Error 1
- The solution of a Java exception has occurred. And error exception in thread when eclipse runs
- java.lang.Throwable: Substituted for the exception com.bea.xml.SchemaTypeLoaderException which lack
- java.lang.ClassNotFoundException : com.mysql.jdbc . driver project cannot connect to database, exception, lack of MySQL driver
- PHP in Windows combined with bat batch processing to achieve multi process verification proxy server function
- Spock + powermock simulation static method reports an error java.lang.classcastexception
- How to Fix LDPlayer4 Proxy Setting Not Work Issue
- Wsimport generates WebService client error [error] can’t connect to socks proxy:http
- The @ Autowired annotation in springboot is invalid in ordinary classes. How to solve and use the null pointer exception java.lang.nullpointerexception
- Nginx reverse proxy MySQL
- Solve the browser err_proxy_connection_failed problem