toHibernate+spring整合出现异常
log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.ClassCastException: $Proxy1 cannot be cast to com.inspur.democreen.dao.impl.TestDaoImpl
at com.inspur.democreen.test.Test.main(Test.java:16)
类型错误
Hi.
I was having a similar problem a few days a go.
I have a class A that implements an interface B. A is managed by spring (a DAO as a matter of fact), and whenever I try to inject an A instance into an A typed field, I get the exact same error.
The workaround I've found was to inject an A instance into a B typed field i.e to inject the instrumented instance (proxy to A) into an interface typed field.
Also, his class already implements an interface (so Spring uses the Java dynamic proxies).
Regards.
I was having a similar problem a few days a go.
I have a class A that implements an interface B. A is managed by spring (a DAO as a matter of fact), and whenever I try to inject an A instance into an A typed field, I get the exact same error.
The workaround I've found was to inject an A instance into a B typed field i.e to inject the instrumented instance (proxy to A) into an interface typed field.
Also, his class already implements an interface (so Spring uses the Java dynamic proxies).
Regards.
来自:
学习spring 依赖注入感受:
依赖的是接口,不依赖实现。
$Proxy1 cannot be cast to com.inspur.democreen.dao.impl.TestDaoImpl
定义一个接口对象,而不是定义 实现接口类的对象,依赖的是接口,不依赖实现,依赖的是描述。