日期:2014-05-18  浏览次数:20680 次

@Resource是如何装配的?
有这样一个类【部分代码】:
@ParentPackage("admin")
public class AccountDetailAction extends BaseAdminAction {
@Resource
private AccountDetailService detailService;

@Resource 既没有指定name,也没有指定type,这里是如何自动装配与其对应的AccountDealServiceImpl的?

还有,执行完Action后,返回到哪一个页面呢?我只在struts.xml中找到如下代码:
<package name="admin" extends="basePackage" namespace="/admin/">
<global-results>
<result name="error" type="freemarker">/WEB-INF/template/admin/error.ftl</result>
<result name="success" type="freemarker">/WEB-INF/template/admin/success.ftl</result>
</global-results>


我想问一下,是不是返回到这里了,不过也不对啊,我看到执行的那个方法返回的是一个类的对象?

啊啊,到底是怎么样的啊?请各位帮我解释解释  在此先谢过啦O(∩_∩)O~

------解决方案--------------------
@Resource
? 例如
@Resource
private DataSource dataSource; // inject the bean named 'dataSource'
? 或者
@Resource(name="dataSource")
@Resource(type=DataSource.class)
? 说明
@Resource 默认按bean 的name 进行查找,如果没有找到会按type 进行查找.

关于跳转页面,如果struts有用到注解,请百度搜“struts注解介绍”(struts2 -convention),否则,按xml配置查看~
只能帮你到这了,呵呵~

------解决方案--------------------
applicationContext.xml 在这个里面声名的 你仔细看看 这些标注是Spring的 不是struts的
------解决方案--------------------
1、@Resouce是有默认注入方式
2、0配置是约定按路径查找页面的  举个例子
  比如你的action的路径是/pp/mm/AccountDetailAction.java  返回页面是return "detail"

  那么你对应的jsp页面是 /pp/mm/AccountDetail-detail.jsp
------解决方案--------------------
@Resource
private AccountDetailService detailService;
这种方式是自动注入的,采用的是按名称去装配注入,,另外还有@Autowried也是注入对象的形式,它采用的是按类型区装配注入对象。。。

至于在struts.xml找不到配置,,是因为该项目用到了sturts零配置的解决方案,lib中加一个struts2-convention-plugin-2.1.8.jar  就可以了,,至于如何实现 以及原理 ,百度上面有很多。。