当前位置: 代码迷 >> Web前端 >> Struts2施用@ParentPackage Unable to locate parent package [test] - [unknown l
  详细解决方案

Struts2施用@ParentPackage Unable to locate parent package [test] - [unknown l

热度:796   发布时间:2012-08-22 09:50:34.0
Struts2使用@ParentPackage Unable to locate parent package [test] - [unknown l

? 今天遇到一个问题我在使用struts2的annotation的@ParentPackage注解的时候,报错:

Caused by: Unable to locate parent package [test] - [unknown location]
 at org.apache.struts2.convention.PackageBasedActionConfigBuilder.getPackageConfig(PackageBasedActionConfigBuilder.java:951)
 at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration(PackageBasedActionConfigBuilder.java:600)
 at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:335)
 at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:53)
 at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:215)
 at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
 ... 22 more

 

?

struts.xml配置:

<struts>
		<constant name="struts.devModel" value="true"></constant>
		<constant name="struts.i18n.encoding" value="UTF-8"></constant>
		
		<!-- <package name="test" extends="struts-default">
			<action name="TestAction" class="test">
				<result name="SUCCESS">${location}</result>
			</action>
		</package> -->
		<package name="test" extends="strust-default" namespace="/test" />
	</struts>

?java代码:

@Scope("prototype")
@Controller("testAction")
@ParentPackage("test")
public class TestAction extends DefaultAction {
    //~ Instance fields ----------------------------------------

    private BaseDAO baseDAO;

    //~ Methods ------------------------------------------------

    /**
     * test
     *
     * @return String
     */
    @Action(value="/execute" , results = {
    		@Result(name = "SUCCESS", location="/success.jsp")
    })
    public String execute() {
        System.out.println("test");

        return SUCCESS;
    }

    /**
     * add test
     *
     * @return
     */
    @Action(value = "/add" , results = {
    		@Result(name = "SUCCESS" , location = "/success.jsp")
    })
    public String add() {
    	getBaseDAO().add(null);
    	
        return SUCCESS;
    }

    /**
     * getter of baseDAO
     *
     * @return the baseDAO
     */
    public BaseDAO getBaseDAO() {
    	if (baseDAO == null){
    		this.baseDAO = (BaseDAO) ApplicationContextUtils.getBean("baseDAO");
    	}
        return baseDAO;
    }
}

?

结果搞了半天没有搞定, 后来我在struts.xml定义package时extends属性改为strust-default,json-default就不报错了

<struts>
		<constant name="struts.devModel" value="true"></constant>
		<constant name="struts.i18n.encoding" value="UTF-8"></constant>
		
		<package name="test" extends="strust-default,json-default" namespace="/test" />
	</struts>

?

?

  相关解决方案