tomcat 部署:
安装好tomcat 后,修改tomcat 的端口
vim conf/server.xml
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
-->
<Connector port="8888" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
启动 tomcat 点击Manager App 返回403错误:
修改tomcat 的config/tomcat-users.xml 文件
添加如下内容:
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<role rolename="manager-jmx"/>
<role rolename="manager-script"/>
<role rolename="manager-status"/>
<user username="admin" password="123456" roles="admin-gui,manager-gui,manager-jmx,
manager-script,manager-status"/>
然后修改 webapps/manager/META-INF/context.xml
<!-- 这里注释
<Context antiResourceLocking="false" privileged="true" >
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
-->
<!-- 添加如下 --->
<Context antiResourceLocking="false" privileged="true" >
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="^.*$" />
</Context>
修改好之后。重启tomcat ,再次访问Manage App ,可以通过 admin / 123456 登陆即可
idea 打war包
pom修改 finalName
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>spring_docker_demo-1.0-SNAPSHOT</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
在原来的 Application 类继承 SpringBootServletInitializer 并实现 configure 方法,完整代码如下:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class,args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
}
打好包之后:
修改 tomcat 中 conf 目录下的配置文件 server.xml,在配置文件中找到Host标签,在其中添加如下内容。这里使用的是相对路径,doBase 属性的值是我们所打 war 包的名称(至于为什么要增加这一步,后面会做解释)。
<Context docBase="analysis-tool-web-1.0-SNAPSHOT" path="/" reloadable="true" privileged="true"/>
如果不做上面的修改,每次访问是要加上项目名称访问:
http://localhost:8080/analysis-tool-web-1.0-SNAPSHOT/login
改了之后呢,我们可以直接访问
在manage app 页面 上传war 包即发布啦
参考链接
网友评论