我在DAO层建立了ProductMgmtImpl类,在SERVICE层建立了ProductserviceImpl类,然后将其配置到spring中的配置文件中
<!-- service -->
  <bean id="productservice"
class="service.impl.ProductserviceImpl">
<property name="dao"
ref="ProductMgmtDAOImpl">
</property>
</bean> 
然后测试ProductserviceImpl类时(测试代码如下)
ApplicationContext factory = new ClassPathXmlApplicationContext(
"applicationContext.xml");
private ProductserviceImpl Productservice= (ProductserviceImpl) factory.getBean("ProductserviceImpl ");总报如下错误
ClassCastException: Proxy cannot be cast to server.impl.ProductserviceImpl
请问为什么从配置文件中读取ProductserviceImpl类时,不能转换成ProductserviceImpl类呢?
                                                                   非常感谢!

解决方案 »

  1.   

    private ProductserviceImpl Productservice= (ProductserviceImpl) factory.getBean("productservice"); 欢迎加入java技术交流群,群号:50701307
      

  2.   

    配置文件里,我的bean名称就是productservice!
      

  3.   

     <bean id="productservice" 
    class="service.impl.ProductserviceImpl"> private ProductserviceImpl Productservice= (ProductserviceImpl) factory.getBean("ProductserviceImpl "); 
    ? <bean id="productservice" 
    class="service.impl.ProductserviceImpl"> private ProductserviceImpl Productservice= (ProductserviceImpl) factory.getBean("productservice");