Spring WebApplicationInitializer and Jetty 8.x

I am trying to deploy an application in Jetty using Maven:

I have a plugin configured as follows:

<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>8.0.4.v20111024</version> </plugin> 

And I have a WebApplicationContextInitializer, I shortened it to a simple form here:

 AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); // Register and map the main dispatcher servlet ServletRegistration.Dynamic dispatcher = container.addServlet("appServlet", new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(2); dispatcher.addMapping("/site/*"); 

When I launch the pier: launch from Spring Tool Suite I cannot access my servlet. Launch Logs:

  [INFO] Configuring Jetty for project: Test [INFO] webAppSourceDirectory C:\Users\Alex\Documents\spring\Test\src\main\webapp does not exist. Defaulting to C:\Users\Alex\Documents\spring\Test\src\main\webapp [INFO] Reload Mechanic: automatic [INFO] Classes = C:\Users\Alex\Documents\spring\Test\target\classes [INFO] Context path = / [INFO] Tmp directory = C:\Users\Alex\Documents\spring\Test\target\tmp [INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml [INFO] Web overrides = none [INFO] web.xml file = null [INFO] Webapp directory = C:\Users\Alex\Documents\spring\Test\src\main\webapp 2012-02-06 21:22:38.048:INFO:oejs.Server:jetty-8.0.4.v20111024 2012-02-06 21:22:38.807:INFO:oejpw.PlusConfiguration:No Transaction manager found - if your webapp requires one, please configure one. 2012-02-06 21:22:41.828:INFO:/:Spring WebApplicationInitializers detected on classpath: [ org.test.application.config.TestWebApplicationInitializer@f946f9 ] 2012-02-06 21:22:41.965:INFO:/:Initializing Spring FrameworkServlet 'appServlet' INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization started INFO : org.springframework.web.context.support.AnnotationConfigWebApplicationContext - Refreshing WebApplicationContext for namespace 'appServlet-servlet': startup date [Mon Feb 06 21:22:41 GMT 2012]; root of context hierarchy INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.s pringframework.beans.factory.support.DefaultListableBeanFactory@ 18b24cb: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization completed in 235 ms 2012-02-06 21:22:42.344:INFO:oejsh.ContextHandler:started omjpJettyWebAppContext{/,file:/C:/Users/Alex/Documents/spring/Test/src/main/webapp/},file:/C:/Users/Alex/Documents/spring/Test/src/main/webapp/ 2012-02-06 21:22:42.344:INFO:oejsh.ContextHandler:started omjpJettyWebAppContext{/,file:/C:/Users/Alex/Documents/spring/Test/src/main/webapp/},file:/C:/Users/Alex/Documents/spring/Test/src/main/webapp/ 2012-02-06 21:22:42.345:INFO:oejsh.ContextHandler:started omjpJettyWebAppContext{/,file:/C:/Users/Alex/Documents/spring/Test/src/main/webapp/},file:/C:/Users/Alex/Documents/spring/Test/src/main/webapp/ 2012-02-06 2012-02-06 21:22:42.352:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0 :8080 STARTING [INFO] Started Jetty Server 

If then go to http: // localhost: 8080 / I get the default Jetty page without any contexts.

I tried to copy webdefaults.xml into my project as described here , but this did not help to solve the problem. It just deleted the default servlet page.

This deploys correctly in Tomcat, so I suspect the problem is in the maven-jetty plugin.

Does anyone have any experience in this area?

Edit:

So I can confirm that if I change the Jetty configuration so that the application is deployed in context / application, then go to http: // localhost: 8080 / application / site / I get 404.

However, the dispatcher servlet registered:

 No mapping found for HTTP request with URI [/application/site/] in DispatcherServlet with name 'appServlet' 

Does this mean that the problem with my controller mappings is correct?

Startup logs show that this mapping is logged:

 Mapped "{[/],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String org.test.application.controller.HomeController.catchAll() 

What am I missing?

+4
source share
1 answer

It seems that the new Jetty plugin uses the "/" root as the root context of the web application, the old one as follows:

contextPath Optional. Contextual path for your webapp. By default, this is installed from the pom.xml project. You can redefine it and set everything you like for it.

0
source

Source: https://habr.com/ru/post/1395097/


All Articles