日期:2014-05-20  浏览次数:20740 次

action如何注入service
1:我的serveice和dao如下
,如何配置action的自动注入,不用写配置文件的,我用了
<context:component-scan base-package="cn.ajicompany" scoped-proxy="interfaces"></context:component-scan>
但是就是注入不了。


@Repository("customerDao")
public class CustomerDaoImpl extends BaseDaoImpl<Customer> implements CustomerDao {

}


@Service("customerService")
public class CustomerServiceImpl implements CustomerService {
@Autowired
private CustomerDao customerDao;
.....
}


public class loginAction extends ActionSupport {

@Autowired
private CustomerService customerService;

------解决方案--------------------
你那个service里面没写setter getter方法
@Autowired setter方法上面
------解决方案--------------------
service实现类里面加这个了吗@Service("xxxxxService")
然后action里面的service接口取名就为这个xxxxxService
------解决方案--------------------
action 也要交給spring管理,加插件包
------解决方案--------------------
web.xml加<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
<!-- default: /WEB-INF/applicationContext.xml -->
</listener>

<context-param>
<param-name>contextConfigLocation</param-name>
<!-- <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value> -->
<param-value>classpath:beans.xml</param-value>
</context-param>
还有就是action也要给spring管理