Multi Maven Spring Config
Я пытаюсь развернуть на сервере одно ухо, которое содержит: ServiceA war ServiceB war springconfig war Я попробовал свой конфиг с одним модулем maven, и он работал, но теперь он не работает с ear и несколькими модулями. Мой Конфиг:
DispatcherConfig
public class DispatcherConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected String[] getServletMappings() {
return new String[]{"/"};
}
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[]{RootConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[]{WebConfig.class};
}
}
RootConfig
@Configuration
@ComponentScan(basePackages = {"com.controllers"},
excludeFilters = {
@ComponentScan.Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class)
})
public class RootConfig {
}
WebConfig
@Configuration
@EnableWebMvc
@ComponentScan("com.controllers")
public class WebConfig
extends WebMvcConfigurerAdapter {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver resolver =
new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/");
resolver.setSuffix(".jsp");
resolver.setExposeContextBeansAsAttributes(true);
return resolver;
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
Ухо пом:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>test-parent</artifactId>
<groupId>test</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<packaging>ear</packaging>
<modelVersion>4.0.0</modelVersion>
<artifactId>earmodule</artifactId>
<dependencies>
<dependency>
<groupId>test</groupId>
<artifactId>serviceA</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>test</groupId>
<artifactId>serviceB</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>test</groupId>
<artifactId>springconfig</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.3.2</version>
<!-- configuring the ear plugin -->
<configuration>
<modules>
<webModule>
<groupId>test</groupId>
<artifactId>serviceA</artifactId>
</webModule>
<webModule>
<groupId>test</groupId>
<artifactId>serviceB</artifactId>
</webModule>
<webModule>
<groupId>test</groupId>
<artifactId>springconfig</artifactId>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
</project>
ServiceA pom (сервис 2 pom похож на этот)
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>test-parent</artifactId>
<groupId>test</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<artifactId>serviceA</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.8.RELEASE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.8.RELEASE</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
контроллер
@Controller
@RequestMapping("/a")
public class ControllerA {
@RequestMapping(value = "aservice", method = RequestMethod.GET)
public String hello() {
System.out.println("Neki log da smo usli u kontroler");
return "aservice";
}
}
Когда я пытаюсь получить доступ к контроллеру, я получаю сообщение:
JBWEB000124: The requested resource is not available.
Журнал во время развертывания:
15:12:46,055 INFO [org.jboss.as.server.deployment] (MSC service thread 1-11) JBAS015876: Starting deployment of "earmodule-1.0-SNAPSHOT.ear" (runtime-name: "earmodule-1.0-SNAPSHOT.ear")
15:12:46,540 INFO [org.jboss.as.server.deployment] (MSC service thread 1-30) JBAS015876: Starting deployment of "null" (runtime-name: "serviceB-1.0-SNAPSHOT.war")
15:12:46,540 INFO [org.jboss.as.server.deployment] (MSC service thread 1-48) JBAS015876: Starting deployment of "null" (runtime-name: "springconfig-1.0-SNAPSHOT.war")
15:12:46,540 INFO [org.jboss.as.server.deployment] (MSC service thread 1-14) JBAS015876: Starting deployment of "null" (runtime-name: "serviceA-1.0-SNAPSHOT.war")
15:12:47,517 WARN [org.jboss.as.ee] (MSC service thread 1-23) JBAS011006: Not installing optional component org.springframework.http.server.ServletServerHttpAsyncRequestControl due to an exception (enable DEBUG log level to see the cause)
15:12:47,518 WARN [org.jboss.as.ee] (MSC service thread 1-23) JBAS011006: Not installing optional component org.springframework.web.context.request.async.StandardServletAsyncWebRequest due to an exception (enable DEBUG log level to see the cause)
15:12:47,562 INFO [org.jboss.web] (ServerService Thread Pool -- 21) JBAS018210: Register web context: /serviceB
15:12:47,562 INFO [org.jboss.web] (ServerService Thread Pool -- 11) JBAS018210: Register web context: /serviceA
15:12:47,585 INFO [org.jboss.web] (ServerService Thread Pool -- 4) JBAS018210: Register web context: /springconfig
15:12:47,596 INFO [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/springconfig]] (ServerService Thread Pool -- 4) 1 Spring WebApplicationInitializers detected on classpath
15:12:47,638 INFO [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/springconfig]] (ServerService Thread Pool -- 4) Initializing Spring root WebApplicationContext
15:12:47,638 INFO [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 4) Root WebApplicationContext: initialization started
15:12:47,649 INFO [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (ServerService Thread Pool -- 4) Refreshing Root WebApplicationContext: startup date [Fri May 19 15:12:47 CEST 2017]; root of context hierarchy
15:12:47,710 INFO [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (ServerService Thread Pool -- 4) Registering annotated classes: [class config.RootConfig]
15:12:47,869 INFO [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (ServerService Thread Pool -- 4) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
15:12:47,929 INFO [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 4) Root WebApplicationContext: initialization completed in 290 ms
15:12:47,930 INFO [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/springconfig]] (ServerService Thread Pool -- 4) Initializing Spring FrameworkServlet 'dispatcher'
15:12:47,930 INFO [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 4) FrameworkServlet 'dispatcher': initialization started
15:12:47,933 INFO [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (ServerService Thread Pool -- 4) Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Fri May 19 15:12:47 CEST 2017]; parent: Root WebApplicationContext
15:12:47,933 INFO [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (ServerService Thread Pool -- 4) Registering annotated classes: [class config.WebConfig]
15:12:48,024 INFO [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (ServerService Thread Pool -- 4) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
15:12:48,189 INFO [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] (ServerService Thread Pool -- 4) Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler]
15:12:48,293 INFO [org.hibernate.validator.internal.util.Version] (ServerService Thread Pool -- 4) HV000001: Hibernate Validator 4.3.2.Final-redhat-1
15:12:48,342 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] (ServerService Thread Pool -- 4) Looking for @ControllerAdvice: WebApplicationContext for namespace 'dispatcher-servlet': startup date [Fri May 19 15:12:47 CEST 2017]; parent: Root WebApplicationContext
15:12:48,472 INFO [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 4) FrameworkServlet 'dispatcher': initialization completed in 542 ms