简体   繁体   English

以编程方式配置嵌入式Tomcat 8应用程序

[英]Embedded Tomcat 8 Application Configured Programmatically

Is there a way to create an application with embedded Tomcat 8 that is configured programmatically (not through a web.xml)? 有没有一种方法可以通过嵌入式Tomcat 8创建应用程序,而该程序是通过编程方式配置的(而不是通过web.xml)? I'm trying to start this application via main() and not through Maven's Tomcat plugin. 我试图通过main()而不是通过Maven的Tomcat插件启动此应用程序。

I honestly don't quite understand what you're trying to do, but Tomcat 8 supports Servlet spec 3.1. 老实说,我不太了解您要做什么,但是Tomcat 8支持Servlet规范3.1。 Anything after spec 3.0 (tomcat 7) can implement a ServletContainerInitializer. 规范3.0(tomcat 7)之后的所有内容都可以实现ServletContainerInitializer。 This should give you what you want. 这应该给您您想要的。

public class ServletInitializer implements ServletContainerInitializer {

public void onStartup(Set<Class<?>> c, ServletContext cx) {
   // register stuff here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM