简体   繁体   English

Spring Boot 战争在外部 tomcat 中出现异常

[英]Spring Boot war giving exception in external tomcat

I have developed a spring boot application in STS ide and i was able to run with the main class without any exception.我在 STS ide 中开发了一个 spring boot 应用程序,我能够毫无例外地与主类一起运行。

@SpringBootApplication
public class Java3Application {
    public static void main(String[] args) {
        SpringApplication.run(Java3Application.class, args);

    }
}

public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        setRegisterErrorPageFilter(false);  
        return application.sources(Java3Application.class);
    }
}

I generated the war of the same project using the below plugin and packaging :我使用以下插件和打包生成了同一个项目的战争:

<packaging>war</packaging>

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

Also have a dependency like this,也有这样的依赖,

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

But the generated war is giving null pointer exception when one of my rest controllers are getting hit, but same is working fine with Main class.但是当我的一个休息控制器被击中时,生成的战争给出了空指针异常,但同样在 Main 类中工作正常。 What is happening in my case??在我的情况下发生了什么? Is my war packaging is wrong or in sufficient??我的战争包装是错误的还是不够的??

To make a spring boot application run in external tomcat, you have to extend it to SpringBootServletInitializer.要使 Spring Boot 应用程序在外部 tomcat 中运行,您必须将其扩展为 SpringBootServletInitializer。 Modify your code as below修改你的代码如下

@SpringBootApplication
public class Java3Application extends SpringBootServletInitializer{
    public static void main(String[] args) {
        SpringApplication.run(Java3Application.class, args);

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM