--以下为spring注入
<bean id="daoImpl" class="orm.base.DAOImpl" >
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="testServiceImpl" class="orm.base.service.impl.TestServiceImpl">
<property name="dao">
<ref bean="daoImpl" />
</property>
</bean>
<bean id="testAction" class="orm.base.action.TestAction">
<property name="testService" ref="testServiceImpl"></property>
</bean>
-- 接口
public interface TestService { public void save(Sshtable s);
}-- 实现类
public class TestServiceImpl implements TestService { private DAO dao;
public DAO getDao() {
return dao;
} public void setDao(DAO dao) {
this.dao = dao;
} public void save(Sshtable s) {
this.getDao().save(s);
}}-- Action中 testService为空
-- 如果用ApplicationContext apc = new ClassPathXmlApplicationContext("applicationContext.xml");
testService = (TestService)apc.getBean("testServiceImpl");
这样就okpublic class TestAction extends BaseAction{ private static final long serialVersionUID = 1L;
private TestService testService;
public String execute(){
testService.save(Object);
return null;
} public TestService getTestService() {
return testService;
} public void setTestService(TestService testService) {
this.testService = testService;
}}
<bean id="daoImpl" class="orm.base.DAOImpl" >
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="testServiceImpl" class="orm.base.service.impl.TestServiceImpl">
<property name="dao">
<ref bean="daoImpl" />
</property>
</bean>
<bean id="testAction" class="orm.base.action.TestAction">
<property name="testService" ref="testServiceImpl"></property>
</bean>
-- 接口
public interface TestService { public void save(Sshtable s);
}-- 实现类
public class TestServiceImpl implements TestService { private DAO dao;
public DAO getDao() {
return dao;
} public void setDao(DAO dao) {
this.dao = dao;
} public void save(Sshtable s) {
this.getDao().save(s);
}}-- Action中 testService为空
-- 如果用ApplicationContext apc = new ClassPathXmlApplicationContext("applicationContext.xml");
testService = (TestService)apc.getBean("testServiceImpl");
这样就okpublic class TestAction extends BaseAction{ private static final long serialVersionUID = 1L;
private TestService testService;
public String execute(){
testService.save(Object);
return null;
} public TestService getTestService() {
return testService;
} public void setTestService(TestService testService) {
this.testService = testService;
}}
解决方案 »
- 菜鸟问题。搞了2天了。求解!!
- strtus1.0里的dispathAction,表单提交时,没有跟参数
- structs 1.2 html:errors
- struts1.3 forward超级怪问题,要多少分都给,只要我有
- java读xml,但xml中有冷僻字读后显示乱码,怎么解决
- Eclipse 3.1.2安装lomboz 3.1.2后 window - preferences不显示lomboz项
- 有项目,有J2EE二年经验的过来接吧!
- 新手问题:JDK和SDK的区别?
- JPA通过外键查询时报错:could not resolve property
- 请大神看看这个程序编辑器的代码该怎么编写 一头雾水
- 眼尖的来看看吧。我快崩溃了。struts2简单配置
- 如何用java实现snmp网络监控协议
会不会是路径的问题呢
朋友有点没明白... 能说的具体些吗?你看我如果加上
<beans default-autowire="byName"><bean id="testService" class="orm.base.service.impl.TestServiceImpl">
<property name="dao">
<ref bean="daoImpl" />
</property>
</bean>这样的话Action中testService就可以注入,这不同样是spring里面注入吗,有点晕了.....