Springboot project to deploy some of the issues on the Jboss

Foreword


Due to the company's problems, reconstructed micro services must be deployed on Jboss, version Jboss EAP 7.1, Springboot 2.1.3.RELEASE. When deployed encountered some problems in this record

 

First, modify the root directory of Jboss application access directory


First jboos modify the default welcome page is empty, otherwise it will conflict, open jboss-eap-7.1 \ standalone \ configuration \ standalone.xml, find

<subsystem xmlns="urn:jboss:domain:undertow:4.0">
            <buffer-cache name="default"/>
            <server name="default-server">
                <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>
                <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
                <host name="default-host" alias="localhost">
                    <location name="/" handler="welcome-content"/>
                    <filter-ref name="server-header"/>
                    <filter-ref name="x-powered-by-header"/>
                    <http-invoker security-realm="ApplicationRealm"/>
                </host>
            </server>
            <servlet-container name="default">
                <jsp-config/>
                <websockets/>
            </servlet-container>
            <handlers>
                <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
            </handlers>
            <filters>
                <response-header name="server-header" header-name="Server" header-value="JBoss-EAP/7"/>
                <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
            </filters>
        </subsystem>

change into

<subsystem xmlns="urn:jboss:domain:undertow:4.0">
            <buffer-cache name="default"/>
            <server name="default-server">
                <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>
                <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
                <host name="default-host" alias="localhost">
                    <!--<location name="/" handler="welcome-content"/>-->
                    <filter-ref name="server-header"/>
                    <filter-ref name="x-powered-by-header"/>
                    <http-invoker security-realm="ApplicationRealm"/>
                </host>
            </server>
            <servlet-container name="default">
                <jsp-config/>
                <websockets/>
            </servlet-container>
            <!--<handlers>
                <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
            </handlers>-->
            <filters>
                <response-header name="server-header" header-name="Server" header-value="JBoss-EAP/7"/>
                <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
            </filters>
        </subsystem>

Remember to back up before the amendment, these comments will be part of the jboss start automatically cleared

At this time, the root path is already empty, we need to project the path mapped to the root path,

Create a new file jboss-web.xml, document reads as follows

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

Our war package with WinRAR to open this file in the WEB-INF directory

At this point start jboss root access path is the path of our project

 

Two, Springboot project packaged into war Notes


<-! Join this playing war package, tell spring-boot tomcat related jar with an external package, do not play into the -> 
< dependency >
< groupId > org.springframework.boot </ groupId >
< artifactId > Spring - Starter-Tomcat-Boot </ the artifactId >
< scope > Provided </ scope >
</ dependency >

 Especially when using non-tomcat container, it must be added to tomcat related packages exclusions, or replaced as above provided, or there will be class cast exception when starting a container

Three, Jboss normal start, but the project did not start SpringBoot


Jboss can see the normal start, but did not identify Springboot project started, this time due to the Jboss not recognize our Servlet

Normal Springboot project startup class is this.

@EnableEurekaServer
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class EurekaApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaApplication.class,args);
    }
}

In this way you can start tomcat container, but not so Jboss start, need to change

@EnableEurekaServer
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class EurekaApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(EurekaApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(EurekaApplication.class,args);
    }
}

Such Jboss can find our Servlet startup

 

Four, Eureka started successfully, but the service can register to access the page blank


...

Can be seen at this time Springboot project has been loaded in, the service also can register normal, but when you open a blank page Eureka

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

这是由于Springboot使用freeMark导致的

解决方案:

yml文件中添加

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

修改后再打包启动

页面可以正常访问

 

Guess you like

Origin www.cnblogs.com/gtblog/p/11237070.html