我无法在嵌入式Tomcat上运行Spring Boot应用程序。到现在为止一切正常,我没有对配置进行任何更改。当我在Eclipse中将其作为Spring Boot App运行时,tomcat在启动过程中立即停止。
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2019-02-06 14:12:20,103 restartedMain ERROR Console contains an invalid element or attribute ""
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.6.RELEASE)
Feb 06, 2019 2:12:23 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Tomcat]
Feb 06, 2019 2:12:23 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.5.16
Feb 06, 2019 2:12:24 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of 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 06, 2019 2:12:24 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring embedded WebApplicationContext
2019-02-06 14:12:24.946 INFO 9504 --- [ restartedMain] o.h.j.i.u.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-02-06 14:12:25.031 INFO 9504 --- [ restartedMain] o.h.Version : HHH000412: Hibernate Core {5.0.12.Final}
2019-02-06 14:12:25.034 INFO 9504 --- [ restartedMain] o.h.c.Environment : HHH000206: hibernate.properties not found
2019-02-06 14:12:25.036 INFO 9504 --- [ restartedMain] o.h.c.Environment : HHH000021: Bytecode provider name : javassist
2019-02-06 14:12:25.089 INFO 9504 --- [ restartedMain] o.h.a.c.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2019-02-06 14:12:25.410 INFO 9504 --- [ restartedMain] o.h.d.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
Feb 06, 2019 2:12:27 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service [Tomcat]
我尝试重新启动计算机,蚀,刷新项目,重新创建.m2存储库,但是它没有帮助我解决问题。
以下是我的配置信息:
主类
@SpringBootApplication
@PropertySource(value="classpath:messages.properties")
public class ExampleApplication {
public static void main(String[] args) {
SpringApplication.run(ExampleApplication.class, args);
}
}
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>
<groupId>com.brokerswing</groupId>
<artifactId>brokerswing</artifactId>
<version>1.1</version>
<name>Example</name>
<description>-</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath />
</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>
<!-- Spring Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Spring Data JPA -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- Spring Email -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- Spring Development Tools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!-- MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Servlet+JSP+JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- Need this to compile JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<!-- Commons Collection -->
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
<!-- Simple Java Mail -->
<!-- <dependency> <groupId>org.simplejavamail</groupId> <artifactId>simple-java-mail</artifactId>
<version>4.4.5</version> </dependency> -->
<!-- Java Mail and JAF -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
<scope>provided</scope>
</dependency>
<!-- Apache Velocity -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<!-- Apache Log4j 2 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
</dependency>
<!-- Excel library -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.6</version>
</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-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<packaging>war</packaging>
</project>
Application.properties
# IDENTITY (ContextIdApplicationContextInitializer)
spring.application.name=Example
server.port=80
#debug=true
# SPRING MVC (WebMvcProperties)
spring.mvc.date-format=DD/MM/YYYY
# JDBC Connection
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/brokerswing?useSSL=false
spring.datasource.username=root
spring.datasource.password=root
# JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
spring.jpa.hibernate.ddl-auto=none
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
# DEVTOOLS (DevToolsProperties)
spring.devtools.restart.enabled=true
spring.devtools.restart.exclude=META-INF/maven/**,META-INF/resources/**,resources/**,static/**,public/**,templates/**,**/*Test.class,**/*Tests.class,git.properties,META-INF/build-info.properties
spring.devtools.restart.poll-interval=5000
spring.devtools.restart.quiet-period=1000
答案 0 :(得分:0)
您收到的错误似乎与SLF4J有关
尝试在pom.xml中添加以下依赖项
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
答案 1 :(得分:0)
在我的情况下,问题的原因是 log4j 的配置错误,主要是由于缺少必需的依赖 commons-collections
依赖项的Maven配置:
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.0</version>
</dependency>
希望此功能对其他访问者有所帮助。