发了两个贴,问题没解决,service与action中注入为null,大家帮看看
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/myedition">
</property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"></ref>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/myEdition/bean/Content.hbm.xml</value>
<value>com/myEdition/bean/ContentType.hbm.xml</value>
<value>com/myEdition/bean/User.hbm.xml</value>
</list>
</property>
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
</bean>
<!-- 定义事务管理器(声明式的事务) -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!-- 配置事务拦截器 -->
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<!--事务拦截器BEAN需要依赖注入一个事物管理器 -->
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<!-- 定义事物传播属性 -->
<props>
<prop key="delete*"> PROPAGATION_REQUIRED</prop>
<prop key="insert*"> PROPAGATION_REQUIRED</prop>
<prop key="update*"> PROPAGATION_REQUIRED</prop>
<prop key="save*"> PROPAGATION_REQUIRED</prop>
<prop key="find*"> PROPAGATION_REQUIRED</prop>
<prop key="*"> PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<!-- 指定哪些bean自动生成业务代理 -->
<property name="beanNames">
<list>
<value>RegeditImpl</value>
<value>SetContentTypeImpl</value>
<value>EditImpl</value>
</list>
</property>
<!-- 下面定义BeanNameAutoProxyCreator所需的事务拦截器-->
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<!--spring beanName dao层的beanName -->
<bean id="UserDAOImpl" class="com.myEdition.dao.impl.UserDAOImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="ContentTypeDAOImpl" class="com.myEdition.dao.impl.ContentTypeDAOImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="ContentDAOImpl" class="com.myEdition.dao.impl.ContentDAOImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- spring容器管理业务逻辑层service -->
<bean id="RegeditImpl" class="com.myEdition.domain.impl.Regeditlmpl">
<property name="UserDAOImpl" ref="UserDAOImpl"></property>
</bean>
<bean id="SetContentTypeImpl" class="com.myEdition.domain.impl.SetContentTypeImpl">
<property name="ContentTypeDAOImpl" ref="ContentTypeDAOImpl"></property>
</bean>
<bean id="EditImpl" class="com.myEdition.domain.impl.EditImpl">
<property name="ContentDAOImpl" ref="ContentDAOImpl"></property>
</bean>
</beans>
[解决办法]
你set方式注入的 <property name="UserDAOImpl" ref="UserDAOImpl"></property>
这name不对吧,能用大写么(没这么写过)
<property name="userDAOImpl" ref="UserDAOImpl"></property>
service层要有对应的
setUserDAOImpl
[解决办法]
private UserDAOImpl UserDAOImpl;这命名不规范!没有这样的
[解决办法]
你这么写的话,dao接口UserDAO还有什么意义
[解决办法]
网上视频Spring IOC 方面多的是,也不难,自己改改就好,你这代码太乱了,不定哪里就有问题。