首页 文章

将spring boot war部署到tomcat

提问于
浏览
0

我正在使用spring boot,我想将一个rest API war文件部署到tomcat服务器中 . tomcat服务器日志中没有错误,但是当我调用任何 endpoints 时,我得到了404“未找到”,并且我从tomcat服务器获得了相同的信息 .

java版本:8 . tomcat版本:9 .

也许我想念一下,这是我的代码示例:

Pom:

<?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.test</groupId>
<artifactId>test</artifactId>
<version>1.1</version>
<packaging>war</packaging>

<name>test</name>
<description>test API</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.1.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-web</artifactId>
    </dependency>



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

        <!-- tag::security[] -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <!-- end::security[] -->


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
</dependencies>

<build>
    <defaultGoal>install</defaultGoal>

    <pluginManagement>
        <plugins>
            <plugin> 
                <groupId>org.springframework.boot</groupId> 
                <artifactId>spring-boot-maven-plugin</artifactId> 
            </plugin> 
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.0.0</version>
            </plugin>

        </plugins>
    </pluginManagement>
    <!-- To use the plugin goals in your POM or parent POM -->
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
 </build>
 </project>

2.Application.java

@SpringBootApplication
public class TestApplication extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder 
application) {
    return application.sources(TestApplication.class);
    }


public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}

}

3 回答

  • 0

    是的我有类似的错误,在我的情况下我自动装配Spring安全会话的对象,所以它显示循环引用错误 . 我在自动装配对象的顶部添加了@Lay注释 . 有关详细信息,请查看链接 .

    https://www.quora.com/How-can-you-fix-Requested-bean-is-currently-in-creation-Is-there-an-unresolvable-circular-reference-while-deploying-a-Spring-Security-application-in-Tomcat

  • 0

    在您的tomcat服务器中运行您的spring boot应用程序作为ROOT上下文 .

    你可以通过使用spring boot app更改tomcat服务器中的ROOT.war(这是一种不好的方式),或者你可以配置它 .

  • 0

    我修复了类似的问题 . 尝试打开网页时没有错误,但有一些警告 . 可能你可以拿"Warning: No mapping found" . 您不需要SpringBootServletInitializer并在应用程序类中覆盖metode . Spring boot是为自动配置而开发的 . 您的html或jsp页面应位于resources / template或resources / static文件夹中 . 请仔细阅读Serving Web Content with Spring MVCthis页面可以帮到你 .

相关问题