第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

設置 Spring Boot Servelet Initializer 時遇到問題

設置 Spring Boot Servelet Initializer 時遇到問題

慕哥6287543 2021-12-01 14:58:03
我正在嘗試使用 Spring Boot 設置一個簡單的 Web CRUD 應用程序。我知道我應該是 spring boot servelet 初始值設定項,但是在日志中,我懷疑它沒有正常運行,因為它沒有記錄我寫的內容。最終目標是讓我能夠訪問http://localhost:8080/LNU-Project/和 home.jsp 顯示。這是 github 上的鏈接。https://github.com/rjpruitt16/LNU-Project/tree/master/src/mainWebAppInitializer.javapackage com.project.LNUProject;    import com.project.LNUProject.config.WebConfig; import lombok.extern.slf4j.Slf4j; 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; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.servlet.DispatcherServlet;    import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRegistration;    @Slf4j     @SpringBootApplication     public class WebAppInitializer extends SpringBootServletInitializer {        private static final String DISPATCHER_SERVLET_NAME = "dispatcher";        public static void main(String[] args) {            SpringApplication.run(WebAppInitializer.class, args);        }        @Override        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {            return application.sources(WebAppInitializer.class);        }        @Override        public void onStartup(ServletContext servletContext) throws ServletException {            log.info("onStartUp");            // create the spring application context            AnnotationConfigWebApplicationContext context =                    new AnnotationConfigWebApplicationContext();            context.register(WebConfig.class);            // create the dispatcher servlet            DispatcherServlet dispatcherServlet =        } }
查看完整描述

2 回答

?
慕神8447489

TA貢獻1780條經驗 獲得超1個贊

請按照以下步驟在外部 tomcat 上部署 Spring Boot 應用程序:


需要打包一個 WAR 應用程序而不是一個 JAR。為此,我們將 pom.xml 更改為以下內容:


<packaging>war</packaging>

添加Tomcat依賴:


<dependency>

  <groupId>org.springframework.boot</groupId>

  <artifactId>spring-boot-starter-tomcat</artifactId>

  <scope>provided</scope>

</dependency>

最后,我們通過實現(xiàn)SpringBootServletInitializer接口來初始化Tomcat所需的Servlet上下文:


 @SpringBootApplication

 public class Application extends SpringBootServletInitializer {


   @Override

   protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {

      return application.sources(Application.class);

     }


   public static void main(String[] args) throws Exception {

    SpringApplication.run(Application.class, args);

   }


}


查看完整回答
反對 回復 2021-12-01
?
阿波羅的戰(zhàn)車

TA貢獻1862條經驗 獲得超6個贊

https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html


該文檔明確指出您必須在 pom.xml中將包裝標簽從pom更改為war


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


    <groupId>com.project</groupId>

    <artifactId>LNU-Project</artifactId>

    <version>0.0.1-SNAPSHOT</version>

    <modules>

        <module>Database</module>

        <module>WEB</module>

    </modules>

    **<packaging>war</packaging>**


    <name>LNU-Project</name>

    <description>Demo project for Spring Boot</description>


    <parent>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-parent</artifactId>

        <version>2.0.6.RELEASE</version>

        <relativePath/> <!-- lookup parent from repository -->

    </parent>


    <properties>

        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <java.version>1.8</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>

        </dependency>


        <dependency>

            <groupId>com.h2database</groupId>

            <artifactId>h2</artifactId>

            <scope>runtime</scope>

        </dependency>

        <dependency>

            <groupId>org.projectlombok</groupId>

            <artifactId>lombok</artifactId>

            <optional>true</optional>

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

            <plugin>

                <groupId>org.apache.maven.plugins</groupId>

                <artifactId>maven-war-plugin</artifactId>

                <version>3.2.0</version>

                <configuration>

                    <failOnMissingWebXml>false</failOnMissingWebXml>

                </configuration>

            </plugin>

            <plugin>

                <groupId>org.codehaus.cargo</groupId>

                <artifactId>cargo-maven2-plugin</artifactId>

                <version>1.6.7</version>

                <configuration>

                    <container>

                        <containerId>tomcat9x</containerId>

                        <type>embedded</type>

                    </container>

                </configuration>

            </plugin>

        </plugins>


    </build>



</project>


查看完整回答
反對 回復 2021-12-01
  • 2 回答
  • 0 關注
  • 189 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

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

公眾號

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