Springboot项目部署在Jboss上的一些问题

前言


由于公司的问题,重构后的微服务必须要部署在Jboss上, 版本为Jboss EAP 7.1,Springboot 2.1.3.RELEASE。部署时候遇到了一些问题,在这记录下来

一、修改Jboss根目录为应用访问目录


首先将jboos的默认欢迎页修改为空,否则会冲突,打开jboss-eap-7.1\standalone\configuration\standalone.xml, 找到

1<subsystem xmlns="urn:jboss:domain:undertow:4.0"> 2 <buffer-cache name="default"/> 3 <server name="default-server"> 4 <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/> 5 <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/> 6 <host name="default-host" alias="localhost"> 7 <location name="/" handler="welcome-content"/> 8 <filter-ref name="server-header"/> 9 <filter-ref name="x-powered-by-header"/> 10 <http-invoker security-realm="ApplicationRealm"/> 11 </host> 12 </server> 13 <servlet-container name="default"> 14 <jsp-config/> 15 <websockets/> 16 </servlet-container> 17 <handlers> 18 <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/> 19 </handlers> 20 <filters> 21 <response-header name="server-header" header-name="Server" header-value="JBoss-EAP/7"/> 22 <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/> 23 </filters> 24 </subsystem>

修改为

1<subsystem xmlns="urn:jboss:domain:undertow:4.0"> 2 <buffer-cache name="default"/> 3 <server name="default-server"> 4 <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/> 5 <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/> 6 <host name="default-host" alias="localhost"> 7 <!--<location name="/" handler="welcome-content"/>--> 8 <filter-ref name="server-header"/> 9 <filter-ref name="x-powered-by-header"/> 10 <http-invoker security-realm="ApplicationRealm"/> 11 </host> 12 </server> 13 <servlet-container name="default"> 14 <jsp-config/> 15 <websockets/> 16 </servlet-container> 17 <!--<handlers> 18 <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/> 19 </handlers>--> 20 <filters> 21 <response-header name="server-header" header-name="Server" header-value="JBoss-EAP/7"/> 22 <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/> 23 </filters> 24 </subsystem>

修改前记得备份,jboss启动后会将这些注释的部分自动清除

此时的根路径已经为空,我们需要将项目路径映射到根路径,

新建一个文件jboss-web.xml,文件内容如下

1<?xml version="1.0" encoding="UTF-8"?> 2<jboss-web> 3 <context-root>/</context-root> 4</jboss-web>

将我们的war包用WinRAR打开,这个文件放到WEB-INF目录下

此时启动jboss访问根路径就是我们的项目路径了

二、Springboot项目打包成war的注意事项


<!-- 打war包时加入此项, 告诉spring-boot tomcat相关jar包用外部的,不要打进去 --><dependency>    <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope></dependency>

 尤其在使用非tomcat容器时,必须加入将tomcat相关包exclusions,或者像上面一样改为provided,否则启动容器时会有类转换异常

三、Jboss正常启动,但没有启动SpringBoot项目


可以看到Jboss正常启动了,但是没有Springboot项目启动的标识,这个时候是由于Jboss无法识别我们的Servlet

正常的Springboot项目启动类是这样的。

1@EnableEurekaServer 2@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) 3public class EurekaApplication { 4 5 public static void main(String[] args) { 6 SpringApplication.run(EurekaApplication.class,args); 7 } 8}

这种方式在tomcat容器中启动可以,但是Jboss无法这样启动,需要改成

1@EnableEurekaServer 2@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) 3public class EurekaApplication extends SpringBootServletInitializer { 4 5 @Override 6 protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 7 return builder.sources(EurekaApplication.class); 8 } 9 10 public static void main(String[] args) { 11 SpringApplication.run(EurekaApplication.class,args); 12 } 13}

这样Jboss启动时才能查找到我们的Servlet

四、Eureka启动成功,可以注册服务但是访问页面空白


...

可以看到此时的Springboot项目已经加载进来,服务也可以正常注册,但打开Eureka页面时一片空白

此时打开控制台发现,访问路径404(这里我没有修改根路径为项目路径,Jboss默认war包名字是访问路径)

这是由于Springboot使用freeMark导致的

解决方案:

yml文件中添加

这个配置的意思是 是否优先从文件系统加载template,默认值为true

修改后再打包启动

页面可以正常访问

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )