Spring Java 配置 : Tomcat deploy without web. xml

标签 spring maven tomcat maven-tomcat-plugin spring-java-config

我构建了一个没有任何 XML 的 java 配置的 Spring MVC 应用程序。我可以毫无问题地在笔记本电脑上部署和启动应用程序。但是,一旦我尝试在我的测试服务器 (tomcat 7) 上部署我的应用程序,我就会收到以下消息:

HTTP Status 404 - The requested resource (/[application context]/) is not available.

我使用 Eclipse Maven 插件构建我的应用程序。是否可以在没有 web.xml 的情况下部署应用程序?如果不能,我真正需要的基本 web.xml 是什么?

Maven WAR 插件:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>${maven.war.plugin.version}</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
</plugin>

WebAppInitializer:

@Order(value = 1)
public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        super.onStartup(servletContext);
    }

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[] { HibernateConfig.class, SecurityConfig.class, HibernateDaoConfig.class };
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[] { WebAppConfig.class };
    }

    @Override
    protected String[] getServletMappings() {
        return new String[] { "/" };
    }

    @Override
    protected Filter[] getServletFilters() {
        return new Filter[]{};
    }
}

更新:catalina.out

Feb 3, 2014 4:18:32 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/[appname]] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.
Feb 3, 2014 4:18:33 PM org.apache.catalina.startup.HostConfig checkResources
INFO: Undeploying context [/[appname]]
Feb 3, 2014 4:18:45 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive [appname].war

最佳答案

如果还没有解决,可能是Servlet版本问题。 Servlet 3.x API 需要能够通过编写 java 类而不是在 WEB-INF 文件夹中包含 web.xml 文件来配置 java web 应用程序。

参见 here一个完整的例子。

关于Spring Java 配置 : Tomcat deploy without web. xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21529577/

相关文章:

java - Weld , Tomcat : missing "beans.xml" in META-INF

java - 当我通过 Eclipse 重新运行应用程序时,Tomcat 会删除我所有上传的图像

java - 在 Spring 集成中主程序本身出现编译时错误

java - 为什么 @Validated + @Component + Implement 会在 Spring Boot 中导致类型误导性错误?

java - 如何在类 Controller 中从 api swagger 实现 spring 注释?

java - 如何使用 Maven 使用其他文件更新现有的 war 文件?

java - 我想知道如何将 tomcat 连接到 oracle jdbc 池

spring - 运行 Spring boot 应用程序时出错 - 创建在类路径资源中定义的名称为 'entityManagerFactory' 的 bean 时出错

java - 如何在 spring 中将集合对象绑定(bind)到 Controller

java - 使用 Maven 进行树外构建。是否可以?