好吧,我在这感觉有点傻,因为我不明白这一点,所以去吧。
我从Spring Initializer下载了最基本的Hello World Spring Boot Web应用程序。我可以使用内部tomcat使它正常运行。但是,当我打包到.war文件并部署到本地的tomcat实例时,该实例类似于生产环境。应用失败。我已经尝试通过文档系统地进行配置更改,以确保上下文正确,并且基本上可以找到解决该问题的其他任何方法。到目前为止,还没有骰子,所以我正在伸出手来看看这里的人是否有见识。
应用程序应从URL http://localhost:8084/clariovista/返回“ TEST CLARIOVISTA”
当我在IDE(Eclipse)中运行它时,没有问题。但是,当我将.war部署到本地tomcat实例时,它抛出500错误,并显示以下消息:
消息请求处理失败;嵌套的异常是org.thymeleaf.exceptions.TemplateInputException:解决模板[错误]时出错,模板可能不存在,或者任何已配置的模板解析器都无法访问该模板
目录树已正确设置。我没有更改Spring Initializer输出给出的任何目录结构。所以我不确定为什么模板位置有问题。除非那是一条红色的鲱鱼,否则还会发生其他事情。
非常感谢您的帮助或见识。
基础知识: SpringBoot 2.1.6。发布, JDK 1.8, Tomcat 8.5.27。
目录树图片。
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 http://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.1.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.inferworks</groupId>
<artifactId>clariovista</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>clariovista</name>
<description>Clario Vista Web</description>
<organization>
<name>Inferworks</name>
<url>Inferworks.com</url>
</organization>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<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>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>${artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
</plugin>
</plugins>
</build>
application.yml
server:
port: 8084
答案 0 :(得分:0)
因为spring-boot-starter-web
通过默认包含spring-boot-starter-tomcat
来包含Tomcat。
如果要在其他Web容器中运行应用程序,则应按如下所示排除Tomcat for Spring MVC:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<!-- Exclude the Tomcat dependency -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
答案 1 :(得分:0)
使用jar文件轻松,命令:maven install
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.dh.Application</mainClass>
<jvmArguments>-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
</jvmArguments>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
答案 2 :(得分:0)
根据您的问题描述,我希望不需要百里香。
2种继续操作的方式。
您要继续使用百里香叶,请添加以下课程并继续部署和 试试看。
@Configuration
public class ThymeleafConfiguration {
private static final String HTML_5 = "HTML5";
@Bean
public SpringTemplateEngine templateEngine() {
final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.addTemplateResolver(templateResolver());
return templateEngine;
}
@Bean
public ThymeleafViewResolver viewResolver(){
final ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
viewResolver.setTemplateEngine(templateEngine());
viewResolver.setViewNames(new String[]{"*.html,*.xhtml,*.txt"});
return viewResolver;
}
@Bean
public SpringResourceTemplateResolver templateResolver() {
// SpringResourceTemplateResolver automatically integrates with Spring's
// own resource resolution infrastructure, which is highly recommended.
final SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
// templateResolver.setApplicationContext(this.applicationContext);
templateResolver.setPrefix("classpath:templates/");
templateResolver.setSuffix(".html");
// HTML is the default value, added here for the sake of clarity.
templateResolver.setTemplateMode(HTML_5);
templateResolver.setCharacterEncoding(CharEncoding.UTF_8);
// Template cache is true by default. Set to false if you want
// templates to be automatically updated when modified.
templateResolver.setCacheable(true);
return templateResolver;
}
}