Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java tapestry spring是否支持Servlet 3.0无XML配置?_Java_Spring_Tapestry - Fatal编程技术网

Java tapestry spring是否支持Servlet 3.0无XML配置?

Java tapestry spring是否支持Servlet 3.0无XML配置?,java,spring,tapestry,Java,Spring,Tapestry,我开始使用SpringMVC编写应用程序,然后决定改用Tapestry。我希望保留我最初使用的无XML配置方法。我第一次尝试这个: public class ServletConfig implements WebApplicationInitializer { @Override public void onStartup(ServletContext servletContext) throws ServletException { // Spring //

我开始使用SpringMVC编写应用程序,然后决定改用Tapestry。我希望保留我最初使用的无XML配置方法。我第一次尝试这个:

public class ServletConfig implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        // Spring //
        AnnotationConfigWebApplicationContext rootContext = new
        AnnotationConfigWebApplicationContext();
        rootContext.register(PersistenceContext.class, ApplicationContext.class);
        servletContext.addListener(new ContextLoaderListener(rootContext));

        // Tapestry //
        servletContext.setInitParameter("tapestry.app-package", "...");
        FilterRegistration.Dynamic filter = servletContext.addFilter("app", TapestrySpringFilter.class);
        filter.addMappingForUrlPatterns(null, false, "/*");
    }
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    // Spring //
    servletContext.setInitParameter("contextClass",
            "org.springframework.web.context.support.AnnotationConfigWebApplicationContext");
    servletContext
            .setInitParameter(
                    "contextConfigLocation",
                    "...config.PersistenceContext ...config.ApplicationContext");

    // Tapestry //
    servletContext.setInitParameter("tapestry.app-package", "...");
    FilterRegistration.Dynamic filter = servletContext.addFilter("app", TapestrySpringFilter.class);
    filter.addMappingForUrlPatterns(null, false, "/*");
}
这里的问题是tapestry使用空构造函数创建另一个ContextLoaderListener。它不采用WebApplicationContext,而是查看contextClass和contextConfigLocation init参数。所以我试了一下:

public class ServletConfig implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        // Spring //
        AnnotationConfigWebApplicationContext rootContext = new
        AnnotationConfigWebApplicationContext();
        rootContext.register(PersistenceContext.class, ApplicationContext.class);
        servletContext.addListener(new ContextLoaderListener(rootContext));

        // Tapestry //
        servletContext.setInitParameter("tapestry.app-package", "...");
        FilterRegistration.Dynamic filter = servletContext.addFilter("app", TapestrySpringFilter.class);
        filter.addMappingForUrlPatterns(null, false, "/*");
    }
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    // Spring //
    servletContext.setInitParameter("contextClass",
            "org.springframework.web.context.support.AnnotationConfigWebApplicationContext");
    servletContext
            .setInitParameter(
                    "contextConfigLocation",
                    "...config.PersistenceContext ...config.ApplicationContext");

    // Tapestry //
    servletContext.setInitParameter("tapestry.app-package", "...");
    FilterRegistration.Dynamic filter = servletContext.addFilter("app", TapestrySpringFilter.class);
    filter.addMappingForUrlPatterns(null, false, "/*");
}
这是什么原因造成的:

 java.lang.IllegalArgumentException: When using the Tapestry/Spring integration library, you must specifiy a context class that extends from org.apache.tapestry5.spring.TapestryApplicationContext. Class org.springframework.web.context.support.AnnotationConfigWebApplicationContext does not. Update the 'contextClass' servlet context init parameter.
TapestryApplicationContext继承自org.springframework.web.context.support.XmlWebApplicationContext。所以我的问题是:有没有办法让基于注释的配置使用这种方法?如果没有,是否有其他方法允许我使用它?还是没有办法避免XML

我试图恢复到我在这里安装的ServletConfig的第一个版本,但是我添加了

servletContext.setInitParameter("tapestry.use-external-spring-context", "true");
我不再收到错误消息,但页面也没有加载。当我尝试加载/app/,而不是加载索引页时,我得到以下结果:

<html>
    <head>
        <title>Error</title>
    </head>
    <body>/app/index.jsp</body>
</html>

错误
/app/index.jsp
我不确定是什么原因造成的,我在日志中找不到任何问题。我想调度服务有点问题。以前有人见过这种错误吗?我不确定这是否与我最初的问题无关,或者这是否是我的方法无效的症状。如果有人能告诉我这是一个单独的问题,我会采取适当的措施。

开箱即用的需要一个XML文件

扩展和覆盖
locateApplicationContext
以返回

然后编写自己的实现,加载新的SpringModuleDef子类

--编辑---

我错了,tapestry spring集成使用
webApplicationContextils.getWebApplicationContext(servletContext)
来查找ApplicationContext。因此,您可以在加载TapestryStringFilter之前使用ApplicationContext初始化servlet上下文,它应该可以正常工作

乙二醇