I am experimenting with the jetty-maven-plugin and no-xml spring configurations, but am having issues using jettys automatic class reloading. When I was using a web.xml everything worked fine.
The WebApplicationInitializer.java replaces the old web.xml
public class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) {
AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
dispatcherContext.register(DispatcherModule.class);
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
ApplicationModule annotated with @Configuration provides configuration for the dispatcher servlet.
@Configuration
@EnableWebMvc
@ComponentScan("com.id.try")
public class DispatcherModule {
@Bean
public InternalResourceViewResolver internalResourceViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/pages/");
resolver.setSuffix(".jsp");
return resolver;
}
}
And finally my pom file to pull in dependencies and configure the jetty-maven-plugin
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<!-- Initial Config: Truncated -->
<properties>
<spring.version>3.2.3.RELEASE</spring.version>
<jetty.plugin.version>8.1.11.v20130520</jetty.plugin.version>
<java.version>1.7</java.version>
<javax.servlet-api.version>3.0.1</javax.servlet-api.version>
</properties>
<dependencies>
<!-- Dependencies Truncated: versions are above -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.plugin.version}</version>
<configuration>
<scanIntervalSeconds>1</scanIntervalSeconds>
<webApp>
<contextPath>/</contextPath>
</webApp>
</configuration>
</plugin>
</plugins>
</build>
</project>
The issue is when I recompile after changing something as simile as a string in a controller, jetty will do as it should when reloading classes, detect the change and restart but it starts with a NullPointerException
java.lang.NullPointerException
at com.id.tryconfiguration.WebAppInitializer.onStartup(WebAppInitializer.java:18)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:180)
at org.eclipse.jetty.plus.annotation.ContainerInitializer.callStartup(ContainerInitializer.java:106)
at org.eclipse.jetty.annotations.ServletContainerInitializerListener.doStart(ServletContainerInitializerListener.java:107)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.util.component.AggregateLifeCycle.doStart(AggregateLifeCycle.java:81)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:96)
at org.eclipse.jetty.server.handler.ScopedHandler.doStart(ScopedHandler.java:115)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:756)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1252)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:710)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494)
at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:293)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.mortbay.jetty.plugin.JettyRunMojo.restartWebApp(JettyRunMojo.java:435)
at org.mortbay.jetty.plugin.JettyRunMojo$1.filesChanged(JettyRunMojo.java:394)
at org.eclipse.jetty.util.Scanner.reportBulkChanges(Scanner.java:691)
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:551)
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:403)
at org.eclipse.jetty.util.Scanner$1.run(Scanner.java:353)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
I have tried excluding the configuration classes and the WebApplicationInitializer.java but it does not help solve the issue.
How can you get SpringMVC working with no-xml and jetty class reloader?
Solved by changing the jetty-maven-plugin to and the source.
<groupId>org.eclipse.jetty</groupId>
<jetty.plugin.version>9.0.4.v20130625</jetty.plugin.version>