代码如下:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
</bean>
<!-- 配置事务管理 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 通知 -->
<tx:advice id="txadvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="all" expression="execution(* com.cstp.service.*.*
(..))"/>
<!-- 加入切入点,和通知配置 -->
<aop:advisor advice-ref="txadvice" pointcut-ref="all"/>
</aop:config>
<!-- dao -->
<bean id="user1DAO" class="com.cstp.impl.User1Impl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- service -->
<bean id="user1Service" class="com.cstp.service.User1ServiceImpl">
<property name="user1DAO" ref="user1DAO"/>
</bean>
<!-- action -->
<bean id="user1Action" class="com.cstp.action.User1Action">
<property name="user1Service">
<ref bean="user1Service"/>
</property>
</bean>
</beans>
public class User1ServiceImpl implements User1Service{
//xml文件中的依赖注入,property="user1DAO"
private User1DAO user1DAO;
public boolean deleteUser(String userid) {
return user1DAO.deleteUser(userid);
}
}
public class User1Impl extends HibernateDaoSupport implements User1DAO{
public boolean deleteUser(String userid){
Session session=null;
//Transaction tr=null;
try {
session=this.getHibernateTemplate().getSessionFactory().openSession();
//tr=session.beginTransaction();
User1 user=(User1) session.get(User1.class, userid);
session.delete(user);
//tr.commit();
return true;
} catch (HibernateException e) {
e.printStackTrace();
/*if(tr!=null){
tr.rollback();
}*/
return false;
}finally{
if(session!=null){
session.close();
}
}
}
省略了接口,serivce接口调用实现类,实现类中有调用了user的接口,从而调用到实现类
<aop:pointcut id="all" expression="execution(* com.cstp.service.*.* (..))"/>,感觉问题就出在那句。你试试这句
<aop:pointcut id="all" expression="execution(* com.cstp.impl..*.* (..))"/>
<aop:pointcut id="all" expression="execution(* com.cstp.service..*.*
(..))"/>
应该是少了个点吧