Java AbstractAnnotationConfigDispatchersServletInitializer与Jetty
我使用的是Jetty 9.1.0.RC2和Spring 4。 使用Java AbstractAnnotationConfigDispatchersServletInitializer与Jetty,java,spring,spring-mvc,embedded-jetty,Java,Spring,Spring Mvc,Embedded Jetty,我使用的是Jetty 9.1.0.RC2和Spring 4。 使用AbstractAnnotationConfigDispatcherServletInitializer并尝试启动以下初始化: Server server = new Server(); WebAppContext webAppContext = new WebAppContext(); webAppContext.setContextPath("/"); webAppContext.setConfigurations(new
AbstractAnnotationConfigDispatcherServletInitializer
并尝试启动以下初始化:
Server server = new Server();
WebAppContext webAppContext = new WebAppContext();
webAppContext.setContextPath("/");
webAppContext.setConfigurations(new Configuration[] { new AnnotationConfiguration() });
webAppContext.setParentLoaderPriority(true);
webAppContext.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/target/classes/.*");
server.setHandler(webAppContext);
server.start();
server.join();
但未能检测到:
No Spring WebApplicationInitializer types detected on classpath
这是一个常见的问题。更多的人面临着这个问题。有时它会导致错误,有时它会给出与
info
相同的信息对于信息,没有问题(就像警告一样)对于错误,发生此错误的原因有多种。我想给你一些解决办法
生成的.类文件兼容性:1.6
”,“源代码”
兼容性:1.6”src/main/webapp/WEB-INF
,它也解决了
这个问题对于tomcat,
tomcat7
插件,但JRE环境是1.6。然后
出现了这个问题。然后您需要将tomcat7
降级到tomcat6
或者将jdk和jre版本升级到1.7停止tomcat
。然后清理项目,
清理服务器
并再次运行项目。有时缓存会造成这种情况
问题按照这种方法,它可能会解决对于JBOSS, @
Sotirios Delimanolis
给出了一个非常好的答案。具体如下:
在典型的servlet应用程序中,您将有一个web.xml
描述符文件来声明您的服务器、过滤器、侦听器、上下文参数、安全配置等。谢谢你的申请。由于Servlet3.0
您可以通过编程来完成大部分工作
Servlet 3.0
提供了可实现的接口ServletContainerInitializer
。servlet容器将在META-INF/services/javax.servlet.ServletContainerInitializer
文件中查找该类的实现,实例化它,并调用它的onStartup()
方法
Spring构建在该接口之上,作为一个适配器/助手
您需要web.xml
描述符或实现WebApplicationInitializer
的类来设置和运行应用程序
资源链接:
以下给出了Jetty的简要详细答案:
不使用web.xml启动servlet上下文
第3版的servlet可以通过编程进行配置,而无需任何web.xml
。
通过Spring及其Java配置,您可以创建一个实现org.springframework.web.WebApplicationInitializer
的配置类。
Spring将自动找到实现该接口的所有类,并启动相应的servlet上下文。更重要的是,搜索这些类的不是Spring,而是servlet容器(例如jetty或tomcat)。
类org.springframework.web.SpringServletContainerInitializer
用
@javax.servlet.annotation.HandleType(WebApplicationInitializer.class
)
并实现javax.servlet.ServletContainerInitializer
根据Servlet 3规范,容器将调用org.springframework.web.SpringServletContainerInitializer.onStartup(设置您可以共享针对此问题的结果吗?您可以发布完整的类吗?您将代码放在AbstractAnnotationConfigDispatchers ServletInitializer的何处?您是否尝试使用此:AnnotationConfigWebApplicationContext
class?您也可以使用此选项。)
javax.websocket.DeploymentException thrown by
org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer
<plugin>
<groupId> org.eclipse.jetty</groupId >
<artifactId> jetty-maven-plugin</artifactId >
<configuration>
<webAppConfig>
<contextPath> /${project.artifactId}</contextPath >
<webInfIncludeJarPattern> busines-letter-*.</webInfIncludeJarPattern >
</webAppConfig>
No Spring WebApplicationInitializer types detected on classpath
Spring WebApplicationInitializers detected on classpath: " + initializers