java - Kotlin Spring Boot 项目不显示 JSP 页面
问题描述
我有一个用 kotlin 编写的 spring boot 项目。用 Java 编写的同一个项目无缝地显示 jsp 页面。但是 kotlin 没有。我的代码如下。kotlin for jsp 页面是否存在兼容性问题?
当我运行我的应用程序时,我没有看到任何错误,但在本地主机上运行,页面只显示“Whitelabel Error Page”。
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>2.4.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<description>Online case record for RHOdisha</description>
<properties>
<java.version>1.8</java.version>
<kotlin.version>1.4.21</kotlin.version>
</properties>
<!--Spring Boot Dependencies -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>dev.miku</groupId>
<artifactId>r2dbc-mysql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!--Kotlin Dependencies-->
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor.kotlin</groupId>
<artifactId>reactor-kotlin-extensions</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-reactor</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.4.1.Final</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-noarg</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
应用程序属性
server.port=1206
logging.level.org.springframework.r2dbc=DEBUG
spring.r2dbc.url=r2dbc:pool:mysql://*ip with db name here*
spring.r2dbc.username= *username*
spring.r2dbc.password= *password*
spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
控制器.kt
@RestController
class ModuleController(
private val appProperties: AppProperties,
private val userService: UserService
) {
@Autowired
var httpSession: HttpSession? = null
private val logger = Logger.getLogger(this.javaClass)
@GetMapping(RouteURL.WELCOME)
fun onAccessView(mView: Model): String? {
return if (SessionUtils.getUserType(httpSession) != null) {
mView.addAttribute("blockName", SessionUtils.getBlockName(httpSession))
"dashboard"
} else {
"redirect:" + RouteURL.HOME
}
}
@GetMapping(RouteURL.SSOBACK)
fun onSsoBack(request: HttpServletRequest): String {
return "redirect:" + request.scheme + "://" + appProperties.appBaseURL()
}
@GetMapping(RouteURL.LOGOUT)
fun onLogout(request: HttpServletRequest): String {
val userId = Conversion.TryCastInteger(SessionUtils.getUserId(httpSession))
SessionUtils.SessionClear(httpSession)
return "redirect:" + request.scheme + "://" + appProperties.appBaseURL() + "/user/logout/" + userId
}
}
解决方案
推荐阅读
- java - 多个不区分大小写的字符串替换
- tensorflow - Conv1D(filters=N, kernel_size=K) 与 Dense(output_dim=N) 层
- javascript - 单击外部引导模式内容时如何重定向?
- c++ - C++ 如何使用类和函数将我的代码转换为 OOP?
- python - 如何在使用 Python 的密钥未知时解析 Json?
- android - 如何在android studio中记录文本文件上的按钮推送?
- react-native - React Native 开关 - 在数据库中将值保存为“是”/“否”而不是“真”/“假”
- azure - 如何在 Azure 容器实例中编辑 /etc/hosts?
- pm2 - pm2 - 文件保存时重新启动(pm2 日志)
- http - HTTP 1.1 是否允许在请求仍然流式传输块时发送响应?