Springboot3.0+spring6.0+JDK17+配置jsp和打war包
由于某些缘故,公司的产品需要升级,但并不希望花费大量时间重写前端代码(原来的就不是前后分离的)。所以虽然spring和springboot都升级为最新的版本,但是依然还是需要支持jsp,并继续用打包为war。
本文中的例子百分百可以执行。
一、概述
升级的理由:
- java1.8已经用得太久了,就快不是长期优先支持的。毕竟1.8已经用了快10年了,该抛弃了
- java17,对于性能的提升是明显的,至少有关资料是这么说的,其次是被优先支持的
- 有关三方技术也渐渐转向jdk17了,例如VSCODE,KAFKA。eclise,sts也不再优先支持1.8
- 团队需要升级技术,不能老是在1.8中打转
- spring5.x已经用太久了,而且有不少缺点;原来的诸多配置需要多个xml文件,有点小繁琐。
- 其它理由
- 老版本的产品依然继续支持
保持war包理由:
- 每次更新的时候,可能就是替换几个class和前端页面,所以没有必要每次拷贝几百M的可执行代码
- 可以更容易调整tomcat的配置,把tomcat的配置从代码中脱离出来。
保持JSP的理由:
- 暂时不想花费大量时间更新前端页面,前端代码量比较大
- jsp没有什么大毛病,虽然spring并不是很推荐它。但spring最新版本,以及tomcat最新版本依然支持着。
- jsp技术,某种意义上,还是比较节约成本的。
本文涉及到几个知识点:
- servlet
- 动态web项目
二、搭建环境
工具和环境:
- 操作系统:windows 11 家庭版
- ide:使用sts即可。本人使用的是Version: 4.14.1.RELEASE版本。
- 容器:tomcat使用最新的10.0.22
- jdk-17
- jquery-3.6.0
本文的例子就是为了升级做准备的,看是否可以比较容易地实现。
大体步骤如下:
- 使用sts,选择"spring starter project ",之后选择有关组件和选项。其中打包的选项选择"war",java选择17。注意,java8依然可以支持
- 修改pom.xml-支持jsp和war包
- 修改启动代码(不修改也可以)
2.1使用spring starter project创建工程
如果不想使用sts,仅仅是想看看有关配置,可以通过https://start.spring.io/在线生成示例。
以下几个图分别是目录结构图,项目配置信息图。
2.1.1目录结构图
修改后的启动代码(原来例子是两个类,现在合并为一个,不合并也可以):
package com.hc.demo; 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 SpringbootJspApplication extends SpringBootServletInitializer { @Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringbootJspApplication.class);
} public static void main(String[] args) {
SpringApplication.run(SpringbootJspApplication.class, args);
} }
这里最关键的是 SpringBootServletInitializer 。
2.1.2项目配置信息-部署
这里的关键是 src/main/webapp目录会映射到/,这个src/main/webapp就是用于存放前端代码的。当然,你要愿意修改为webContent,myhtml之类都可以,只要做好部署映射即可。
其它build path,java compiler略过。
2.1.3项目配置信息-project facets
注意:”dynamic web module"不要选择太老的,选择5.0即可。
这个"dynamic web mouule 5.0“意味着可以支持:
2.1.4项目配置信息-配置web上下文
首先打开"servers"视图,然后添加tomcat10,之后就可以设置上下文:
点击“edit”可以设置上下文。根据项目配置不同和sts的配置不同,有的时候,也可以在项目设置页面中直接设置上下文。
2.2修改pom.xml
这里是关键,以下是本例的pom.xml的内容:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.hc.demo</groupId>
<artifactId>springjsp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>springjsp</name>
<description>Demo project for Spring boot and jsp and war</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency> <!-- 以下1~4是为了支持jsp -->
<!-- 1添加servlet依赖模块 -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>10.0.22</version>
</dependency>
<!-- 2添加jstl标签库依赖模块 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!--3添加tomcat依赖模块.-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<!-- 4使用jsp引擎,springboot内置tomcat没有此依赖 -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>compile</scope>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- 配置war包插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warSourceExcludes>src/main/resources/**</warSourceExcludes>
<warName>springjsp</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
</pluginRepositories> </project>
主要是两个地方要修改:
- 配置jsp
- 配置war插件
以上两个修改,分类如以下两个地方:
2.2.1配置jsp
<!-- 以下1~4是为了支持jsp -->
<!-- 1添加servlet依赖模块 -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>10.0.22</version>
</dependency>
<!-- 2添加jstl标签库依赖模块 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!--3添加tomcat依赖模块.-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<!-- 4使用jsp引擎,springboot内置tomcat没有此依赖 -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>compile</scope>
</dependency>
此外,因为这里引入了"spring-boot-starter-tomcat",所以需要把它从“spring-boot-starter-web”移除掉,具体见完整pom.xml。
2.2.2配置war插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warSourceExcludes>src/main/resources/**</warSourceExcludes>
<warName>springjsp</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
三、编写测试代码
3.1编写过滤器
具体过程略,一些列出过滤器代码:
package com.hc.demo.config.filter; import java.io.IOException; import org.springframework.web.filter.OncePerRequestFilter; import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; public class MyFilter extends OncePerRequestFilter { @Override
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
HttpServletRequest request2 = (HttpServletRequest) request;
String orgin = request2.getHeader("origin");
HttpServletResponse res = (HttpServletResponse) response;
res.addHeader("Access-Control-Allow-Origin", orgin);
res.addHeader("Access-Control-Allow-Methods", "*");
res.addHeader("Access-Control-Allow-Headers", "content-type"); String url=request.getRequestURI().toString();
System.out.println(url);
FilterRequest req = new FilterRequest(request);
filterChain.doFilter(req, response);
}
}
注:
1.红色部分代码是为了便于观察过滤器是否生效。
2.在jdk17中,“servlet”的顶级包名以“jakarta"开头,这是一个很大的区别。
3.2编写一个接口
具体过程略,先列出控制器代码:
package com.hc.demo.student.controller; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import com.hc.demo.student.service.StudentService; @Controller
@RequestMapping(value = "/student")
public class StudentController {
@Autowired
private StudentService studentService; @RequestMapping(value = "list")
@ResponseBody
public Object list() {
return studentService.queryAll();
}
}
3.3编写一个jsp页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jsp测试</title>
</head>
<style>
html, body {
width: 100%;
height: 100%;
} .jsp-example {
display: flex;
color: red;
font-size: 32px;
height: 20%;
margin-top: 10%;
margin-bottom:4px;
line-height: 50%;
text-align: center;
background-color: yellow;
flex-direction: column-reverse;
flex-wrap: wrap;
align-content: center;
justify-content: center;
}
#studentTable{
border-width: 4px;
border-style: solid;
border-color: lightgray;
width: 400px;
margin: 0 auto;
}
tr,td,th{
border-width: 1px;
border-style: solid;
border-color: lightgray;
text-align:center;
}
</style> <body>
<div class="jsp-example" id="dDivExample"></div>
<div id="dDivStudent">
<table id="studentTable">
<thead>
<tr>
<th>姓名</th>
<th>性别</th>
</tr>
</thead>
<tbody id="studentTableBody">
</tbody>
</table> </div>
</body>
<script src="/springjsp/plugin/jquery/jquery-3.6.0.min.js"></script>
<script>
$(function () {
document.getElementById("dDivExample").innerText="这是一个springboot3.0+jdk17+jsp+war的测试";
showStudent();
});
function showStudent(){
$.ajax({
url: '/springjsp/student/list',
type: 'POST',
dataType: 'json',
async: true,
success: function (rs, status, xhr) {
let htmlText="";
for(let i=0,len=rs.length;i<len;i++){
htmlText+="<tr><td>"+rs[i].NAME+"</td><td>"+rs[i].sex+"</td></tr>\n"
}
let _body=document.getElementById("studentTableBody");
_body.innerHTML=htmlText;
},
error: function (rs) {
alert("失败!");
}
});
}
</script> </html>
3.4配置wms
package com.hc.demo.config; import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; import com.hc.demo.config.filter.MyFilter; @Configuration
public class MyWMS extends WebMvcConfigurationSupport { @Override
protected void addInterceptors(InterceptorRegistry registry) {
} @Override
public void addViewControllers(ViewControllerRegistry registry) {
// 为根增加默认的 映射,指向index.html
registry.addViewController("/").setViewName("index");
} @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/")
.addResourceLocations("classpath:/temploates/");
registry.addResourceHandler("/plugin/**").addResourceLocations("/plugin/");
super.addResourceHandlers(registry);
} /**
* 注册过滤器
* @return
*/
@Bean
public FilterRegistrationBean<MyFilter> registerAuthFilter() {
FilterRegistrationBean<MyFilter> registration = new FilterRegistrationBean<>();
MyFilter filter=new MyFilter();
registration.setFilter(filter);
registration.addUrlPatterns("/*");
registration.setName("authFilter");
registration.setOrder(1); //值越小,Filter越靠前。
return registration;
}
}
上文红色部分是需要关注的地方,分别设置根url,静态资源和过滤器。
注意:这是springboot3.0+spring6.0和以往的一个大区别:以前的版本过滤器设置需要新建一个web.xml,并在web.xml中配置过滤器。但是现在不需要了,这个无疑非常方便,非常合理。
当然这主要是因为 5.0的web moudule可以避免配置web.xml(这个有点烦人)。
四、打包
新建debug Configurations,如下图:
”jre“部分,”VM arguments"设置参数"-Dmaven.test.skip=true",避免无谓的测试。
其它设置大概如下:
- goals- clean compile package,这是清理、编译,最后打包
- jdk-17
- 字符集-utf-8
- jrebel 关闭
之后,点击“debug”,则运行如下:
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< com.hc.demo:springjsp >------------------------
[INFO] Building springjsp 0.0.1-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/apache/maven/plugins/maven-clean-plugin/3.2.0/maven-clean-plugin-3.2.0.pom
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.2.0/maven-clean-plugin-3.2.0.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.2.0/maven-clean-plugin-3.2.0.pom (5.3 kB at 1.5 kB/s)
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/apache/maven/plugins/maven-plugins/35/maven-plugins-35.pom
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/35/maven-plugins-35.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/35/maven-plugins-35.pom (9.9 kB at 1.8 kB/s)
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/apache/maven/maven-parent/35/maven-parent-35.pom
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/35/maven-parent-35.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/35/maven-parent-35.pom (45 kB at 4.2 kB/s)
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/apache/apache/25/apache-25.pom
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/apache/25/apache-25.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/apache/25/apache-25.pom (21 kB at 5.5 kB/s)
[INFO]
[INFO] --- maven-clean-plugin:3.2.0:clean (default-clean) @ springjsp ---
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar (169 kB at 7.0 kB/s)
[INFO] Deleting E:\codes-java\git\learning\gitee\springjsp\target
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ springjsp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ springjsp ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to E:\codes-java\git\learning\gitee\springjsp\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ springjsp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ springjsp ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to E:\codes-java\git\learning\gitee\springjsp\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ springjsp ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) @ springjsp ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ springjsp ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-war-plugin:3.3.2:war (default-war) @ springjsp ---
[INFO] Packaging webapp
[INFO] Assembling webapp [springjsp] in [E:\codes-java\git\learning\gitee\springjsp\target\springjsp-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [E:\codes-java\git\learning\gitee\springjsp\src\main\webapp]
[INFO] Building war: E:\codes-java\git\learning\gitee\springjsp\target\springjsp.war
[INFO]
[INFO] --- spring-boot-maven-plugin:3.0.0-SNAPSHOT:repackage (repackage) @ springjsp ---
[INFO] Downloading from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-buildpack-platform/3.0.0-SNAPSHOT/maven-metadata.xml
[INFO] Downloaded from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-buildpack-platform/3.0.0-SNAPSHOT/maven-metadata.xml (2.4 kB at 1.5 kB/s)
[INFO] Downloading from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-buildpack-platform/3.0.0-SNAPSHOT/spring-boot-buildpack-platform-3.0.0-20220626.095848-608.pom
[INFO] Downloaded from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-buildpack-platform/3.0.0-SNAPSHOT/spring-boot-buildpack-platform-3.0.0-20220626.095848-608.pom (3.4 kB at 2.5 kB/s)
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/net/java/dev/jna/jna-platform/5.7.0/jna-platform-5.7.0.pom
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/net/java/dev/jna/jna-platform/5.7.0/jna-platform-5.7.0.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/net/java/dev/jna/jna-platform/5.7.0/jna-platform-5.7.0.pom (0 B at 0 B/s)
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/net/java/dev/jna/jna/5.7.0/jna-5.7.0.pom
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/net/java/dev/jna/jna/5.7.0/jna-5.7.0.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/net/java/dev/jna/jna/5.7.0/jna-5.7.0.pom (0 B at 0 B/s)
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/tomlj/tomlj/1.0.0/tomlj-1.0.0.pom
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/tomlj/tomlj/1.0.0/tomlj-1.0.0.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/tomlj/tomlj/1.0.0/tomlj-1.0.0.pom (0 B at 0 B/s)
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/antlr/antlr4-runtime/4.7.2/antlr4-runtime-4.7.2.pom
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/antlr/antlr4-runtime/4.7.2/antlr4-runtime-4.7.2.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/antlr/antlr4-runtime/4.7.2/antlr4-runtime-4.7.2.pom (0 B at 0 B/s)
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/antlr/antlr4-master/4.7.2/antlr4-master-4.7.2.pom
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/antlr/antlr4-master/4.7.2/antlr4-master-4.7.2.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/antlr/antlr4-master/4.7.2/antlr4-master-4.7.2.pom (0 B at 0 B/s)
[INFO] Downloading from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-loader-tools/3.0.0-SNAPSHOT/maven-metadata.xml
[INFO] Downloaded from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-loader-tools/3.0.0-SNAPSHOT/maven-metadata.xml (2.4 kB at 1.4 kB/s)
[INFO] Downloading from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-loader-tools/3.0.0-SNAPSHOT/spring-boot-loader-tools-3.0.0-20220626.095848-608.pom
[INFO] Downloaded from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-loader-tools/3.0.0-SNAPSHOT/spring-boot-loader-tools-3.0.0-20220626.095848-608.pom (2.3 kB at 1.4 kB/s)
[INFO] Downloading from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-buildpack-platform/3.0.0-SNAPSHOT/spring-boot-buildpack-platform-3.0.0-20220626.095848-608.jar
[INFO] Downloading from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-loader-tools/3.0.0-SNAPSHOT/spring-boot-loader-tools-3.0.0-20220626.095848-608.jar
[INFO] Downloaded from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-loader-tools/3.0.0-SNAPSHOT/spring-boot-loader-tools-3.0.0-20220626.095848-608.jar (247 kB at 39 kB/s)
[INFO] Downloaded from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-buildpack-platform/3.0.0-SNAPSHOT/spring-boot-buildpack-platform-3.0.0-20220626.095848-608.jar (240 kB at 35 kB/s)
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/net/java/dev/jna/jna-platform/5.7.0/jna-platform-5.7.0.jar
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/net/java/dev/jna/jna/5.7.0/jna-5.7.0.jar
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/tomlj/tomlj/1.0.0/tomlj-1.0.0.jar
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/antlr/antlr4-runtime/4.7.2/antlr4-runtime-4.7.2.jar
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/codehaus/plexus/plexus-utils/1.5.8/plexus-utils-1.5.8.jar
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/net/java/dev/jna/jna-platform/5.7.0/jna-platform-5.7.0.jar
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/net/java/dev/jna/jna/5.7.0/jna-5.7.0.jar
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/tomlj/tomlj/1.0.0/tomlj-1.0.0.jar
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/antlr/antlr4-runtime/4.7.2/antlr4-runtime-4.7.2.jar
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.5.8/plexus-utils-1.5.8.jar
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/tomlj/tomlj/1.0.0/tomlj-1.0.0.jar (0 B at 0 B/s)
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/net/java/dev/jna/jna/5.7.0/jna-5.7.0.jar (0 B at 0 B/s)
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/net/java/dev/jna/jna-platform/5.7.0/jna-platform-5.7.0.jar (0 B at 0 B/s)
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/antlr/antlr4-runtime/4.7.2/antlr4-runtime-4.7.2.jar (0 B at 0 B/s)
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.5.8/plexus-utils-1.5.8.jar (268 kB at 38 kB/s)
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:31 min
[INFO] Finished at: 2022-07-04T22:06:59+08:00
[INFO] ------------------------------------------------------------------------
五、测试
5.1安装和配置tomcat10
安装过程略。
主要是设置JAVA_HOME和日志编码。
5.1.1设置JAVA_HOME
打开TOMCAT10的bin\catalina.bat,在”setlocal"下插入一句:
set JAVA_HOME=D:\soft\develop-tool\java\jdk-17.0.3.1
5.1.2设置日志编码
打开tomcat10\conf\logging.properties,把所有的“UTF-8”修改为“GBK"即可。
5.2部署war包
把前面打包的E:\codes-java\git\learning\gitee\springjsp\target\springjsp.war复制到tomcat10\webapps下。
5.3运行war包
在cmd下,运行tomcat10下的startup.bat,当然之前,需要先打开Mysql。
控制台输出如下:
看起来很正常,默认8080已经打开。
切换到浏览器,输入:http://localhost:8080/springjsp/
结果如下图:
运行 正常。
六、小结
整个过程很顺利,麻烦的地方仅仅是配置pom.xml和在wms中配置静态资源。
和以前版本比起来,的确方便了不少。例如不要配置web.xml(实际上web module>=3.1即可),这样可以节省servlet,filter之类的配置。
Springboot3.0+spring6.0+JDK17+配置jsp和打war包的更多相关文章
- IDEA 工具项目的配置及如何打war包
1. Project Structure 1.1 首先点击File-ProjectStructure,进入项目配置: 2.Project Settings配置 2.1 Project 2.1.1 f ...
- 在linux下把jsp文件 打包war格式(centos7)
在linux下把jsp文件 打成war包 chmod -R 777 /data/jdk8u242-b08/bincd /data/TongWeb61712/deployment/TestCase//d ...
- 配置数据库连接池,Tomcat6.0 连接池的配置
Tomcat6.0 连接池的配置1.本人当前使用的Tomcat版本为:6.0.20,oracle为稳定的9i版本 2.下文为方便起见,依习惯以%Tomcat_Home%表示Tomcat安装的目录,本人 ...
- Tomcat7.0/8.0 详细安装配置图解,以及UTF-8编码配置
Tomcat7.0/8.0 详细安装配置图解,以及UTF-8编码配置 2017年01月24日 10:01:48 阅读数:51265 标签: tomcattomcat安装tomcat配置tomcat编码 ...
- JDK1.6.0+Tomcat6.0的安装配置
JDK1.6.0+Tomcat6.0的安装配置是如何进行的呢?我们按照下面几个步骤来: 1.安装JDK 这是进行JSP开发的重要一步,也是安装JSP引擎(Tomcat.Resin.Weblogic等) ...
- SpringBoot3.0 + SpringSecurity6.0+JWT
JWT_SpringSecurity SpringBoot3.0 + SpringSecurity6.0+JWT Spring Security 是 Spring 家族中的一个安全管理框架. 一般We ...
- WCF学习之旅—WCF4.0中的简化配置功能(十五)
六 WCF4.0中的简化配置功能 WCF4.0为了简化服务配置,提供了默认的终结点.绑定和服务行为.也就是说,在开发WCF服务程序的时候,即使我们不提供显示的 服务终结点,WCF框架也能为我们的服务提 ...
- Redis 3.0 Cluster集群配置
Redis 3.0 Cluster集群配置 安装环境依赖 安装gcc:yum install gcc 安装zlib:yum install zib 安装ruby:yum install ruby 安装 ...
- elasticsearch5.0.0 安装插件及配置过程
elasticsearch5.0.0 安装插件及配置过程 由于es5.0是里程碑式的更新,所以很多变化的地方,暂时我就插件安装遇到的问题记录一下. 插件安装命令 2.3版本的安装命令 安装Marvel ...
- Spring4.0编程式定时任务配置
看过很多定时调度的配置,大多使用XML配置,觉得比较麻烦,也比较老套.这里介绍一种基于spring4.0注解编程式配置定时任务,简单清晰,使用方便.. 至于引入spring相关jar这里不多说,直接切 ...
随机推荐
- 读书笔记 dotnet 的字符串在内存是如何存放
本文是读伟民哥翻译的 .NET内存管理宝典 这本书的笔记,我认为读书的过程也需要实践,这样对一知半解的知识也有较为清晰的了解.在阅读到 string 在内存的布局时,我看到 RuntimeHelper ...
- Mysql带条件取多条随机记录
有个文章段落表part,有两种类型的段落,即part_type取1或2,要从表中随机取多条任意类型的段落,比如3条. 方法一 ORDER BY后接RAND() select * from part w ...
- 基于FPGA的音乐蜂鸣器设计
蜂鸣器是一种一体化结构的电子讯响器,采用直流电压供电,广泛应用于计算机.打印机.复印机.报警器.电子玩具.汽车电子设备.电话机.定时器等电子产品中作发声器件. 图1 :蜂鸣器实物图 蜂鸣器主要分为压电 ...
- 🔥 PyTorch神操作:一图秒懂Tensor变形记!
亲爱的码农小伙伴们,你们是否还在为Tensor的各种变换头大如斗?别怕,今天给大家送上一张超实用的PyTorch变换秘籍图,让你的Tensor操作如行云流水,CPU和GPU之间的切换如穿梭自如! GP ...
- SqlServer2008R2 在开始菜单中找不到配置管理器
直接找到C:\Windows\SysWOW64\SQLServerManager10.msc,打开即可.
- WEB服务与NGINX(5)- root和alias的区别详解
root和alias的区别 root:指定站点家目录,给定的路径对应于location中的/uri 左侧的/,文件的绝对路径为root+location. 支持环境:http, server, loc ...
- 热烈祝贺 Splashtop 赢得最佳远程桌面用户满意度得分
在 G2 的 2021 年冬季远程桌面网格报告中,Splashtop 的净发起人得分(NPS)为 93,是所有远程桌面工具中最高的. 在一份分析用户对 30 多种远程桌面解决方案的评论的报告中,Spl ...
- 策略梯度玩 cartpole 游戏,强化学习代替PID算法控制平衡杆
cartpole游戏,车上顶着一个自由摆动的杆子,实现杆子的平衡,杆子每次倒向一端车就开始移动让杆子保持动态直立的状态,策略函数使用一个两层的简单神经网络,输入状态有4个,车位置,车速度,杆角度,杆速 ...
- QShop商城--项目介绍
QShop商城-项目介绍 QShop商城,是全新推出的一款轻量级.高性能.前后端分离的电商系统,支持微信小程序,前后端源码100%开源,完美支持二次开发,让您快速搭建个性化独立商城. 技术架构:.Ne ...
- CSS——float浮动属性
流动布局 流动模型(Flow),即文档流,浏览器打开HTML网页时,从上往下,从左往右,逐一加载. 在正常情况下,HTML元素都会根据文档流来分布网页内容的. 文档流有2大特征: ① 块状元素会随着浏 ...