Java – embedded jetty 8 x / Spring MVC / WebApplicationInitializer

Does anyone have the following work samples:

>Embedded jetty 8 X Application > use spring MVC > zero XML configuration (that is, use spring webapplicationinitializer on the servlet side and annotations / Java configuration on the spring side)

I've tried all possible combinations, but I can't make it work Most of the embedded jetty examples I've found are based on 7 X or still use XML configuration files The best setting I have now is to create a webappcontext and set the configuration to annotation configuration This shows something actually happening on the console, but it can't find my webapplicationinitializer class, and it must be on the classpath This is based on jetty 8.1 4 and spring 3.1 two

For testing purposes, the webapplicationinitializer class doesn't do much. It just prints something in the onstartup method to check if it's loading

thank you!

Solution

You see this question: Spring 3.1 webapplicationinitializer & embedded jetty 8 annotationconfiguration?

I can't share my code, but here are some codes to help you:

On the 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 version:

<spring.version>3.1.2.RELEASE</spring.version>
<jetty.version>8.1.5.v20120716</jetty.version>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>