有这样一个类【部分代码】:
@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="freeer">/WEB-INF/template/admin/error.ftl</result>
<result name="success" type="freeer">/WEB-INF/template/admin/success.ftl</result>
</global-results>
我想问一下,是不是返回到这里了,不过也不对啊,我看到执行的那个方法返回的是一个类的对象?啊啊,到底是怎么样的啊?请各位帮我解释解释  在此先谢过啦O(∩_∩)O~

解决方案 »

  1.   

    @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配置查看~
    只能帮你到这了,呵呵~
      

  2.   

    applicationContext.xml 在这个里面声名的 你仔细看看 这些标注是Spring的 不是struts的
      

  3.   

    1、@Resouce是有默认注入方式
    2、0配置是约定按路径查找页面的  举个例子
      比如你的action的路径是/pp/mm/AccountDetailAction.java  返回页面是return "detail"  那么你对应的jsp页面是 /pp/mm/AccountDetail-detail.jsp
      

  4.   

    我之前是这样弄的:
    1,在applicationContext.xml中配置:
    <bean id="userService" class="com.oa.service.impl.UserService" init-method="init" destroy-method="destroy"> <!-- 注入接口的实现(Spring_doc) -->
         <property name="userDao">
           <ref bean="userDao"/>
         </property>
    </bean>
        <!-- Actions below  userAction使用@autowire可自动装配 --> <bean name="userAction" class="com.oa.struts.action.UserAction"  scope="prototype" autowire="default">  
       <property name="userService">
       <ref bean="userService"/>    
       </property>
    </bean>
    UserAction 里面有一个userService接口,根据这里的配置,用到的时候,装配一个UserService类
    2,在struts.xml中这样配:
    <action name="user" class="userAction">
            <result name="success">/index.jsp</result>但是现在如果用@Resource
    自动装配的话我就不知道是怎么弄的了。
    @Resource
    private AccountDetailService detailService;//这里是个接口,怎么调用到对应的类的方法的呢?
    然后,执行完了之后,又是返回到哪个页面的呢?配置在哪里的呢?
    也不知道说清楚没有,各位  帮帮忙  谢谢了【我在struts.xml 与applicationcontext.xml文件中都找过了,没找到相应的配置啊  还有,applicationcontext.xml这个只是配置bean吧,也可以配置返回地址吗?】
      

  5.   

    @Resource
    private AccountDetailService detailService;
    这种方式是自动注入的,采用的是按名称去装配注入,,另外还有@Autowried也是注入对象的形式,它采用的是按类型区装配注入对象至于在struts.xml找不到配置,,是因为该项目用到了sturts零配置的解决方案,lib中加一个struts2-convention-plugin-2.1.8.jar  就可以了,,至于如何实现 以及原理 ,百度上面有很多。。
      

  6.   

    嗯  现在了解了 
    因为在struts.xml中做了如下配置
    <!-- 结果资源的路径 -->
    <constant name="struts.convention.result.path" value="/WEB-INF/template/" />引入struts2-convention-plugin-2.1.8.jar包,并且采用了0配置,所以会到该目录下找到对应的文件【文件名通过返回值来判定】 菜鸟一枚 呵呵 谢谢各位 O(∩_∩)O~