gpt4 book ai didi

java - Spring Boot 应用程序未加载到独立的 tomcat 中

转载 作者:行者123 更新时间:2023-11-28 23:22:06 26 4
gpt4 key购买 nike

我正在尝试在独立的 tomcat 中运行一个简单的 spring boot 应用程序。我已经尝试按照引用文档和此处的一些问题/答案进行操作,但似乎没有任何效果。当 tomcat 启动时,它会部署应用程序但完全忽略我的应用程序类,因此不会加载任何 spring 代码。我确定它一定是我遗漏的简单东西,但是......?

这是日志文件中的相关输出:

INFO: Deploying web application archive C:\dev\servers\apache-tomcat-7.0.75\webapps\bankweb-0.1.war
Feb 15, 2017 4:41:45 PM org.apache.catalina.startup.TldConfig execute
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list o
f JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and
JSP compilation time.
Feb 15, 2017 4:41:45 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive C:\dev\servers\apache-tomcat-7.0.75\webapps\bankweb-0.1.war has finished in 3,595
ms

我已经根据文档更新了 Application 类以扩展 SpringBootServletInitializer:

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application extends SpringBootServletInitializer {

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

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

private static Class<Application> applicationClass = Application.class;
}

@RestController
class GreetingController {

@RequestMapping("/hello/{name}")
String hello(@PathVariable String name) {
return "Hello, " + name + "!";
}
}

在 pom 中,我将包装更改为 war 并将嵌入式 servlet 容器标记为已提供:

<?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>it.ankle</groupId>
<artifactId>bankweb</artifactId>
<version>0.1</version>
<packaging>war</packaging>

<name>demo</name>
<description>Demo project for Spring Boot</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.7</java.version>
<tomcat.version>7.0.69</tomcat.version>
</properties>

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</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>
</plugins>
</build>
</project>

最佳答案

这已解决,用户错误几乎概括了它。我剥离了所有东西以删除所有可选的 Spring 模块,让它工作,然后一点一点地添加所有东西并且它工作了。我还不太习惯这种 spring boot 的东西,但是仅仅因为你在 pom.xml 文件中配置了一个库就包含了功能。感谢所有花时间阅读的人!

关于java - Spring Boot 应用程序未加载到独立的 tomcat 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42255701/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com