我有一个Spring Boot应用程序。它在2台服务器上运行。这两台服务器具有相同的配置。其中一台可以正常工作......在另一台上,启动时出现此异常
2016-04-26 08:24:17.633 ERROR [localhost-startStop-1]: Error starting Tomcat context: org.springframework.beans.factory.BeanCreationException
2016-04-26 08:24:17.903 ERROR [main]: Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)
at it.besmart.parkserver.StartServer.main(StartServer.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:54)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:99)
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:76)
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:457)
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:168)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:160)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130)
... 14 more
堆栈跟踪持续了很多行,大多数情况下,我在自动连接和注入活动中遇到了问题,并找到了根本原因
Invocation of init method failed; nested exception is org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
但我的www.example.com文件是:db.properties file is:
jdbc.driverClassName = com.mysql.jdbc.Driver
jdbc.url = jdbc:mysql://192.168.3.240:3306/SMARTPARK?useSSL=false
jdbc.username = parkuser
jdbc.password = xxxxxxxxxxxxxxxx
hibernate.dialect = org.hibernate.dialect.MySQLDialect
hibernate.show_sql = false
hibernate.format_sql = false
数据库正在运行(第二台服务器定期连接到数据库..),用户和主机的所有权限均正确
这是我的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>it.besmart</groupId>
<artifactId>eparkserver</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>eparkserver</name>
<description>ePark server</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<start-class>it.besmart.parkserver.StartServer</start-class>
<!--
<tomcat.version>8.0.29</tomcat.version>
-->
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-core</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>server-copy</id>
<goals>
<goal>run</goal>
</goals>
<phase>package</phase>
<configuration>
<target>
<echo message="Push to server /home/pi/park/" />
<scp trust="yes" todir="pi:sofia2011@192.168.3.67:/home/pi/park/">
<fileset dir="${basedir}/target">
</fileset>
</scp>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.9.6</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
我所有的休眠设置都在HibernateConfiguration.class中(我将这个应用程序从Spring MVC迁移到了Spring Boot)
@Configuration
@EnableTransactionManagement
@ComponentScan({ "it.besmart" })
@PropertySource(value = { "classpath:db.properties" })
public class HibernateConfiguration {
@Autowired
private Environment environment;
@Bean
public LocalSessionFactoryBean sessionfactory(){
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
sessionFactory.setPackagesToScan(new String[] {"it.besmart.models"});
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(environment.getRequiredProperty("jdbc.driverClassName"));
dataSource.setUrl(environment.getRequiredProperty("jdbc.url"));
dataSource.setUsername(environment.getRequiredProperty("jdbc.username"));
dataSource.setPassword(environment.getRequiredProperty("jdbc.password"));
return dataSource;
}
private Properties hibernateProperties() {
Properties properties = new Properties();
properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
return properties;
}
@Bean
@Autowired
public HibernateTransactionManager transactionManager(SessionFactory s) {
HibernateTransactionManager txManager = new HibernateTransactionManager();
txManager.setSessionFactory(s);
return txManager;
}
}
我不知道发生了什么
8条答案
按热度按时间scyqe7ek1#
也许你可以通过改变你的项目sdk来避免这种情况。
在我的项目中,我最初使用java-11-openjdk-amd 64作为我的JDK,也遇到了同样的问题。
在将JDK更改为java-8-oracle后,它工作正常。
d7v8vwbk2#
我也有同样的问题。加上这个:
ctrmrzij3#
在我的例子中,项目使用的是
Java 8
,但在我的配置中它被设置为Java 11
。转到项目结构-〉项目-〉项目SDK并更改java版本。我希望它能有所帮助。hgncfbus4#
1)当使用Spring Boot时,您不应该直接包含其他Spring依赖项,而是依赖于Boot自己的依赖项管理。当使用提供的"启动器"时,您可以确保所有需要的库都包含在匹配的版本中。文档:www.example.comhttps://spring.io/guides/gs/spring-boot/#use-maven
2)日程安排指南不是一个Web应用程序,所以你可能在你的pom.xml中有一些来自REST指南的发霉的东西?
一个"好的" pom应该有"spring-boot-starter-web"(为了方便),或者所有包含在启动器中的依赖项都单独列出。只要检查一下你有它们。还要确保你在你的SpringApplication中包含一个@EnableAutoConfiguration。把要在Object数组中运行的类添加到SpringApplication的run方法中:(新对象[] {应用程序.类,调度任务.类},参数);SpringApplication.run(new Object[]{Application.class, ScheduledTasks.class}, args);
享受:)
tvz2xvvm5#
在src/main/resources下添加名为www.example.com的新文件application.properties
删除
HibernateConfiguration
类并在主类上添加@EnableTransactionManagement
注解。fjnneemd6#
可能是关于'starter-web'和嵌入式tomcat之间的servlet.jar冲突,请使用以下代码。
zujrkrfu7#
突然我遇到了同样的错误,但对我来说,这是依赖下面,只是回答这里,以节省别人浪费时间
Spring启动开发工具
llmtgqce8#
如果有人和我一样愚蠢,结果是tomcat初始化使用默认属性来 Boot ,包括操作系统、内核等数据。
默认情况下,java会自动初始化这些值,但是可以使用
System.setProperties(newProps);
覆盖它们这把我的雄猫弄坏了...