有没有人有以下的工作样本:
>嵌入式Jetty 8.x应用程序
>使用Spring MVC
>零XML配置(即在Servlet端使用Spring WebApplicationInitializer,在Spring端使用annotations / java配置)
我已经尝试了所有可能的组合,但我不能让它工作.我发现的大多数嵌入式jetty示例都基于7.x或仍然使用XML配置文件.我现在获得的最佳设置是创建WebAppContext并将配置设置为AnnotationConfiguration.这在控制台上显示实际发生了某些事情,但它无法找到我的WebApplicationInitializer类,而它肯定在类路径上.这是基于Jetty 8.1.4和Spring 3.1.2.
出于测试目的,WebApplicationInitializer类没有做太多工作,它只在onStartup方法中打印一些内容来检查是否正在加载它.
谢谢!
解决方法
你看到这个问题:
Spring 3.1 WebApplicationInitializer & Embedded Jetty 8 AnnotationConfiguration?
在web.xml
<!-- Java-based Spring container deFinition --> <context-param> <param-name>contextClass</param-name> <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value> </context-param> <!-- Location of Java @Configuration classes that configure the components that makeup this application --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>com.workable.config</param-value> </context-param>
清空application-config.xml:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"> </beans>
Spring WebMVCConfig:
/** * Spring MVC Configuration. * */ @Configuration @EnableWebMvc @EnableAsync @EnableScheduling public class WebMvcConfig extends WebMvcConfigurerAdapter { } /** * Main configuration class for the application. * Turns on @Component scanning,loads externalized application.properties. */ @Configuration @ComponentScan(basePackages = { "com.workable" },excludeFilters = {@Filter(Configuration.class)}) public class MainConfig { ... }
Lib版本:
<spring.version>3.1.2.RELEASE</spring.version> <jetty.version>8.1.5.v20120716</jetty.version>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。