是否有人有以下的工作样本:
我已尝试过所有可能的组合,但我无法让它发挥作用。我发现的大多数嵌入式jetty示例都基于7.x或仍然使用XML配置文件。我现在获得的最佳设置是创建WebAppContext并将配置设置为AnnotationConfiguration。这在控制台上显示实际发生了某些事情,但它无法找到我的WebApplicationInitializer类,而它肯定在类路径上。这是基于Jetty 8.1.4和Spring 3.1.2。
出于测试目的,WebApplicationInitializer类没有做太多工作,它只在onStartup方法中打印一些东西来检查是否正在加载它。
谢谢!
答案 0 :(得分:1)
您是否看到了这个问题: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>