Spring Boot (iv): Package deployment

Source: Internet
Author: User

Springboot packaging and deployment one, jar package

Pom File in Packaging:

1. Compile into the project directory and use the following command:
//命令打包(-Dmaven.test.skip=true 跳过测试)mvn clean package -Dmaven.test.skip=true或者执行Maven install
2. The target of running the current directory has a. jar file #启动命令
nohub java -jar xxxx.jar >/dev/null 2>&1 &
Ii. War Pack 1, modify package (a), modify packet type
<!-- <packaging>jar</packaging> --><packaging>war</packaging>
(b), remove the built-in Tomcat plugin
<Dependency><Groupid>org.springframework.boot</Groupid><Artifactid>spring-boot-starter-web</Artifactid><!--removing Tomcat plugins--<Exclusions><Exclusion><Groupid>org.springframework.boot</Groupid><Artifactid>spring-boot-starter-tomcat</Artifactid></exclusion> </ exclusions></dependency>< Span class= "hljs-comment" ><!--removed after the error, add the following dependency--><<groupid>javax.servlet </groupid> < artifactid>javax.servlet-api</ artifactid> <scope>provided< /scope></DEPENDENCY>   

2. Modify the Startup class

Inheriting the Springbootservletinitializer class, overriding the Configure () method
Package Top. Lrshuai. Blog; Import org. mybatis. spring. annotation. Mapperscan; Import org. springframework. Boot. Springapplication; Import org. springframework. Boot. autoconfigure. Springbootapplication; Import org. springframework. Boot. Builder. Springapplicationbuilder; Import org. springframework. Boot. Context. Embedded. Configurableembeddedservletcontainer; Import org. springframework. Boot. Context. Embedded. Embeddedservletcontainercustomizer; Import org. springframework. Boot. Web. servlet. ErrorPage; Import org. springframework. Boot. Web. Support. Springbootservletinitializer;import org.springframework .http.run (Application.class, args) .configure (builder) .sources (This.getClass ()) 
3. Compile (a), and compile the jar, mvn clean package -Dmaven.test.skip=true(b), (there is another, mvn clean install -Dmaven.test.skip=true4, deploy into Tomcat's WebApps directory, start Tomcat, fix three, possible problems (a), is static file resource access 404 Solution: All links are written relative to the path, perhaps you have written this way before <link href="/css/blog.css" rel="stylesheet" >Yes, I think it's okay to pack the jar, but the war is going to be a problem. <link href="../static/css/blog.css" rel="stylesheet" th:href="@{/css/blog.css}">(b), the other is the path of JS, such as the AJAX request. There's a problem with the path. My scenario: 1. Add this line to the head of the page <meta name="_ctx" th:content="@{/}" />2, JS get its path,
<script type="text/javascript">var _ctx = $("meta[name=‘_ctx‘]").attr("content");_ctx = _ctx.substr(0, _ctx.length - 1);</script>
3. Then add in front of each AJAX request _ctx。 Like what: url = "/article/add"would instead url = ctx+"/article/add"

Spring Boot (iv): Package deployment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.