我在spring的dao模版注入到工厂会报属性设置有错
配置如下
<!-- 业务逻辑组件 -->
<bean id="loginUserService" parent="txProxyTemplate">
<property name="target">
<bean class="com.my.service.impl.LoginUserImpl">
<property name="userDao" ref="userDao" />
</bean>
</property>
</bean>
<!-- 注入业务组件到工厂 -->
<bean id="serviceFactory" class="com.my.service.ServiceFactory">
<property name="loginUser" ref="loginUserService" />
</bean>
工厂类
public class ServiceFactory { private LoginUserImpl loginUser;
/**
* user service组件工厂
* @param args
*/
public ILoginUser getUserService(String parameter){
if(parameter.equalsIgnoreCase("login"))
{
return new LoginUserImpl();
}if(parameter.equals("manager"))
{
return null;
}
return null;
}
/**
* 工厂模式注入实现类
* @param loginUserServiceImpl
*/ public void setLoginUser(LoginUserImpl loginUser) {
this.loginUser = loginUser;
}
错误信息:
Error creating bean with name 'serviceFactory' defined in ServletContext resource [/WEB-INF/classes/spring/spservice_user.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy5] to required type [com.my.service.impl.LoginUserImpl] for property 'loginUser']
PropertyAccessExceptionsException (1 errors)
org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy5] to required type [com.my.service.impl.LoginUserImpl] for property 'loginUser'
配置如下
<!-- 业务逻辑组件 -->
<bean id="loginUserService" parent="txProxyTemplate">
<property name="target">
<bean class="com.my.service.impl.LoginUserImpl">
<property name="userDao" ref="userDao" />
</bean>
</property>
</bean>
<!-- 注入业务组件到工厂 -->
<bean id="serviceFactory" class="com.my.service.ServiceFactory">
<property name="loginUser" ref="loginUserService" />
</bean>
工厂类
public class ServiceFactory { private LoginUserImpl loginUser;
/**
* user service组件工厂
* @param args
*/
public ILoginUser getUserService(String parameter){
if(parameter.equalsIgnoreCase("login"))
{
return new LoginUserImpl();
}if(parameter.equals("manager"))
{
return null;
}
return null;
}
/**
* 工厂模式注入实现类
* @param loginUserServiceImpl
*/ public void setLoginUser(LoginUserImpl loginUser) {
this.loginUser = loginUser;
}
错误信息:
Error creating bean with name 'serviceFactory' defined in ServletContext resource [/WEB-INF/classes/spring/spservice_user.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy5] to required type [com.my.service.impl.LoginUserImpl] for property 'loginUser']
PropertyAccessExceptionsException (1 errors)
org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy5] to required type [com.my.service.impl.LoginUserImpl] for property 'loginUser'
<!-- 业务逻辑组件 -->
<bean id=dao class="com.my.service.impl.LoginUserImpl" parent="txProxyTemplate">
<property name="userDao" ref="userDao" />
</bean> <bean id="loginUserService" parent="txProxyTemplate">
<property name="dao">
<ref local="dao"/>
</property>
</bean>
我看你对dao分层结构不太清楚,是初学者吧,配置文件的配置也错了,bean没有嵌套配置的
定义一个事物模版,struts2d的ACTION直接调用都可以,中间加上工厂就不行。