亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Spring Boot 應用程序在 IDE 中運行時工作,但當部署為 war 文件時

Spring Boot 應用程序在 IDE 中運行時工作,但當部署為 war 文件時

飲歌長嘯 2023-03-17 16:05:39
好吧,我在這里感覺有點傻,因為我想不通,所以就開始吧。我從 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.Release,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>
查看完整描述

3 回答

?
元芳怎么了

TA貢獻1798條經驗 獲得超7個贊

使用 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>


查看完整回答
反對 回復 2023-03-17
?
慕桂英546537

TA貢獻1848條經驗 獲得超10個贊

根據您的問題描述,我希望不需要百里香。

您可以通過 2 種方式進行。

  1. 如果確實不需要,則從 pom.xml 中刪除 thymeleaf 模板文件夾和 thymeleaf 依賴項并繼續。

  2. 你想繼續使用 thymeleaf,請添加下面的類并繼續部署并嘗試。

@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;

    }


}


查看完整回答
反對 回復 2023-03-17
?
POPMUISE

TA貢獻1765條經驗 獲得超5個贊

因為默認spring-boot-starter-web包含 Tomcat 。 如果你想在其他 web 容器中運行你的應用程序,你應該為 Spring MVC 排除 Tomcat,如下所示: spring-boot-starter-tomcat


<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>


查看完整回答
反對 回復 2023-03-17
  • 3 回答
  • 0 關注
  • 153 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號