你这样配置一下,没有写DAO,SERVICE层的接口,我没有测试过,spring在注入的对象的时候是一个实现了一个接口的类,在ACTION中要是用这个对象定义的是一个接口变量。它的意思就是,我定义一个抽象的接口只有方法,然后注入的是这个接口具体实现的业务功能。试一试下面的:
<bean id="testDAO" class="com.dao.TestDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean> <bean id="testServiceTarget" class="com.service.TestService">
<property name="testDAO">
<ref local="testDAO" />
</property>
</bean> <bean id="testService" parent="traProxyTemplate">
<property name="target">
<ref local="testServiceTarget" />
</property>
</bean>
<bean id="testDAO" class="com.dao.TestDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean> <bean id="testServiceTarget" class="com.service.TestService">
<property name="testDAO">
<ref local="testDAO" />
</property>
</bean> <bean id="testService" parent="traProxyTemplate">
<property name="target">
<ref local="testServiceTarget" />
</property>
</bean>
试试在事务模板上直接写上Target怎样
<bean id="testService" parent="traProxyTemplate">
<property name="target">
<bean class="com.service.TestService">
<property name="ccpccjgbjrkdDao">
<ref bean="testDAO"/>
</property>
</bean>
</property>
</bean>
<property name="testDAO">
<ref local="testDAO" />
</property>
</bean>
在配置文件中这样写出错,大概意思是说testDAO在com.service.TestService中找不到
我在TestService中有声明testDAO呀。这是怎么回事?
private TestDAO testDAO;public void setTestDAO(TestDAO dao){
this.testDAO = dao;
}
我这样做了,但是现在的问题是web启动后出现死循环
有人遇到这个问题么?帮帮小弟。
public class TestService {
private ApplicationContext context = null;
private TestDAO testDAO = null;
public TestService() {
context = new FileSystemXmlApplicationContext("D:/workspace/hibernate+spring/WebRoot/WEB-INF/classes/applicationContext.xml");
setTestDao(TestDAO.getFromApplicationContext(context));
} public void deleteTest(){
com.bean.Test test = new Test();
test.setId(4);
test.setData("dd");
test.setDates(new Date());
testDAO.save(test);
test.setId(5);
test.setData("dd000000000000000000000000000000000000000");
test.setDates(new Date());
testDAO.save(test);
}
public TestDAO getTestDao() {
return testDAO;
}
public void setTestDao(TestDAO testDao) {
this.testDAO = testDao;
}
程序启动后出现死循环,web页面根本无法相应???????
TestService service = context .getBean("testService");service.deleteTest();
这样的吗?
配置文件,我觉的tcmis(难道你忘了吗?) 说的应该没有问题
TestService service = context .getBean("testService");
service.deleteTest();
配置也是按tcmis(难道你忘了吗?) 的说法配置
但是运行
public void deleteTest(){
Test test = new Test();
test.setId(4);
test.setData("dd");
testDao.save(test);test.setId(5);test.setData("dd000000000000000000000000000000000000000");
testDao.save(test);
}
并没有会滚 还是有一条记录插进去了。