Put the springboot project into the war package and put it into the tomcat to run and start, the solution to the js css png can not be loaded

How to achieve the war package in the springboot project, below I provide a link, you can refer to it yourself.
It is important to talk about the title.
First, just put the war file in the webapps folder, and then double-click the file in the bin folder

Insert picture description here
to start the war package. After
the first startup, open the project and note that the path is http://localhost:8080 (tomcat configuration file server. The port number in the xml configuration file

Insert picture description here
)/(the prefix of the war package name in the webapps folder) to start the project.
For example, mine is

Insert picture description here
the path where I started the project is http://localhost:8080/lock
After opening the project, I found that static resources such as js, css, png, etc. could not be loaded. At this time, just
add this to the host tag in the server.xml file

<Context docBase="F:\apache-tomcat-8.5.56\webapps/lock/WEB-INF/classes/static/bower_components/" path="/bower_components/"/>
    <Context path="/dist/" docBase="F:\apache-tomcat-8.5.56\webapps/lock/WEB-INF/classes/static/dist/"/>

Configure it. As shown below:
Insert picture description here

The background color of the idea log is adjusted. The
idea springboot project is started, and the breakpoint is invalid. The
springboot project opens the war package: The
war package is deployed to tomcat for operation:

In this life, persistence or non-persistence is not terrible, what is afraid is to walk alone on the road of persistence! ! !

Guess you like

Origin blog.csdn.net/taiguolaotu/article/details/115030939