先说下我的情况struts.xml中配置后台的action
<action name="hello" class="loginAction">
<result name="success">/jsp/success.jsp</result>
</action>
这里的class如果对应成class本来的路径action.LoginAction是没有错误
我现在是把这个class对应成spring为我注册的bean,看下后台的LoginAction配置
controller会默认为我注册一个名字为loginAction的bean 
@Controller
@Scope(value="prototype")
public class LoginAction extends ActionSupport {

@Autowired
private LoginService service; @Override
public String execute() throws Exception {

ApplicationContext ct = new ClassPathXmlApplicationContext("applicationContext.xml");
System.out.println("ct===="+ct.toString());
System.out.println("action已经被注册了======"+ct.getBean("loginAction"));

service.loginUser("你好", "123");
return SUCCESS;
}
当我直接访问的时候 他会出500错误 如下
java.lang.ClassNotFoundException: loginAction
我的spring配置文件中配置如下
<context:annotation-config />
<context:component-scan base-package="action,dao,service"/>
我把action换成他实际对应的包路径的时候 去后台拿
ct.getBean("loginAction")时发现 后台会提示
INFO XmlBeanDefinitionReader:315 - Loading XML bean definitions from class path resource [applicationContext.xml]
也就是这个时候才开始去加载appicationContext.xml
所以我猜测的是容器启动时spring并没有去为我注册bean所以会导致我找不到对应的action
web.xml如下
 <listener >
        <listener-class >org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
不知道哪位大大能给我指点一下 

解决方案 »

  1.   


    @Controller("baseCodeMAction")
    @Scope("prototype")
    @SuppressWarnings("unchecked")
    public class BaseCodeMAction extends BaseAction {
    @Resource(name="baseCodeMServiceImpl")
    private BaseCodeMService baseCodeMService;
    <action name="baseCodeM_*" class="baseCodeMAction" method="{1}">
    <result name="goList">/page/common/Base_Code/codeMQuery.jsp</result>
    <result name="goEdit">/page/common/Base_Code/codeMUpdate.jsp</result>
    <result name="goAdd">/page/common/Base_Code/codeDAdd.jsp</result>
    <result name="goFK">/page/common/Base_Code/codeMAdd.jsp</result>
    </action>
      

  2.   

    我在这里附上搭建的小框架吧,只有spring3.1.0和struts2.2.3连数据库都没有(只有10K+),只有简单的注解注入配置希望有空的大大帮我审视一下……
    我从网上看了好多配置和我一样的,不晓得他为啥老是会说struts.xml中的action