Does anyone have a working sample of the following:
I have tried every possible combination, but I can't get this to work. Most embedded jetty examples I found are based on 7.x or still use XML configuration files. The best setup I got now is to create a WebAppContext and set the configuration to AnnotationConfiguration. This shows on the console that something is actually happening, but it cannot find my WebApplicationInitializer class while it definitely is on the classpath. This was based on Jetty 8.1.4 and Spring 3.1.2.
For testing purposes, the WebApplicationInitializer class doesn't do much, it only prints something in the onStartup method to check if this is being loaded.
Thanks!
Did you see this question : Spring 3.1 WebApplicationInitializer & Embedded Jetty 8 AnnotationConfiguration ?
I can't share my code but here is some code that may help you :
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>
Empty 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 versions :
<spring.version>3.1.2.RELEASE</spring.version>
<jetty.version>8.1.5.v20120716</jetty.version>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With