春季启动战争不适用于EAP 6



我使用spring-boot创建了一个基于REST的小型应用程序。该应用程序作为war包部署在EAP6(JBoss)上。由于EAP6是基于Java 1.7的,我已经在我的maven pom中配置了它来编译和使用Java 1.7版本。当我部署应用程序时,我可以在服务器日志中看到控制器正在注册,但当我点击它时,我会得到404。另外,JBoss并没有获取我的上下文根配置,而是将应用程序名称作为上下文根号。我测试了所有可能的终点,但一切都是404。有人能给我提些能帮助我继续前进的建议吗?

POM文件:

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.7</java.version>
</properties>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

应用程序配置

package com.org.orderhistory.v2.orderhistory.v2;
import ...
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

}

package com.org.orderhistory.v2.orderhistory.v2.controllers;
import ...
@RestController
@RequestMapping(value="/myorder/weborders")
public class WebOrderControllers {
@RequestMapping(value="/{webUserId}",method = RequestMethod.GET, produces = "application/json")
public List<WebOrder> getWebOrdersForUser(@PathVariable Long webUserId) {

JBoss日志

2017-10-09 02:24:29,744 [ServerService Thread Pool -- 594] INFO  [org.springframework.boot.web.servlet.FilterRegistrationBean] Mapping filter: 'requestContextFilter' to: [/*]
2017-10-09 02:24:30,368 [ServerService Thread Pool -- 594] INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5a46b924: startup date [Mon Oct 09 02:24:27 EDT 2017]; root of context hierarchy
2017-10-09 02:24:30,451 [ServerService Thread Pool -- 594] INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] Mapped "{[/org/weborders/{webUserId}],methods=[GET],produces=[application/json]}" onto public java.util.List<com.org.www.order.model.WebOrder> com.org.orderhistory.v2.orderhistory.v2.controllers.WebOrderControllers.getWebOrdersForUser(java.lang.Long)

这里的问题完全相同。试试这个:

1。在pom.xml中:

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>

2.添加一个类实现WebApplicationInitializer:

@Configuration
public class WebApplicationInitializerImpl implements WebApplicationInitializer{
@Override 
public void onStartup(ServletContext container) throws ServletException {
WebApplicationContext context = getContext();
Dynamic registration = container.addServlet("dispatcher", new DispatcherServlet(context));
registration.setLoadOnStartup(1);
registration.addMapping("/*");
} 
private WebApplicationContext getContext() { 
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setConfigLocation(ApplicationMain.class.getName());
return context;
} 
}

3.记住通过您的应用程序扩展SpringBootServletInitializer:

@SpringBootApplication
public class ApplicationMain extends SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(ApplicationMain.class);
}
public static void main(String[] args) {
SpringApplication.run(ApplicationMain.class, args);
}
}

如果它有效,那么问题与dispatcherServlet有关
使用Spring引导时,应该自动配置dispatcherServlet。(这是自动配置的一部分)
根据Redhat的解释,这种情况似乎是jboss的问题:

因为JBoss强制执行servlet规范的要求,即即使对于它自己的服务器添加的DefaultServlet,也不要注册冲突的映射。

要检查您的dispatcherServlet是否按预期注册,请尝试以下操作:

[standalone@localhost:9999 /] /deployment=spring-boot-application.war/subsystem=web:read-resource(recursive=true)

不工作:

{
"outcome" => "success",
"result" => {
"context-root" => "/spring-boot-application",
"servlet" => undefined,
"virtual-host" => "default-host"
}
}

工作:

{
"outcome" => "success",
"result" => {
"context-root" => "/spring-boot-application",
"virtual-host" => "default-host",
"servlet" => {"appServlet" => {
"servlet-class" => "org.springframework.web.servlet.DispatcherServlet",
"servlet-name" => "appServlet"
}}
}
}

希望它能解决你的问题

参考:
https://access.redhat.com/solutions/1211203
https://blog.csdn.net/u011160656/article/details/78809239

相关内容

最新更新