现在的工程很多都是前后端分离的工程,后端更多的微服务的角色。但还是有一些工程会使用jsp,thymeleaf 这样的作为页面展示。这篇记录了该类型的搭建
主要结构如下:
jsp放在webapp/WEB-INF/jsp里
applicaion.properties
主要是配置jsp的解析的路径
spring.mvc.view.suffix=.jsp
spring.mvc.view.prefix=/WEB-INF/jsp/
gradle 的配置(maven的配置是一样的)
plugins {
id 'org.springframework.boot' version '2.1.7.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
war{
baseName ="demo" //war名称
}
dependencies {
//如果想在jboss里运行起来需要加入
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
//如果想在内嵌的tomcat里启动并且能解析jsp的话,需要加入这句。并且注释到上面的那行引入
//compile('org.apache.tomcat.embed:tomcat-embed-jasper')
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
developmentOnly("org.springframework.boot:spring-boot-devtools")
}
注意
dependencies 里的配置,在jboss里启动和main方法(内置的tomcat)启动不同。
配置到jboss里步骤
1.edit configurations
2.
3.
在jboss里启动后默认的web context是
http://localhost:8080/demo-0.0.1/
如果需要改成http://localhost:8080/demo
可以加个jboss-web.xml到webapp下
<jboss-web>
<context-root>demo</context-root>
</jboss-web>