java Spring boot 应用程序不启动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39861549/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring boot application does not start
提问by besmart
I have a Spring Boot application which we install in some little servers for our products. It has always worked. This evening we have installed it in one of our servers and it did not start.
我有一个 Spring Boot 应用程序,我们将它安装在我们产品的一些小型服务器中。它一直有效。今晚我们将它安装在我们的一台服务器上,但它没有启动。
Every server is an image from a common image, so the OS is the same.
每个服务器都是来自一个公共映像的映像,因此操作系统是相同的。
When we launch the .jar we are getting:
当我们启动 .jar 时,我们得到:
Oct 05, 2016 11:16:45 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Oct 05, 2016 11:16:45 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.5.5
Oct 05, 2016 11:16:46 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring embedded WebApplicationContext
Oct 05, 2016 11:17:03 AM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Tomcat
This is our application.properties which regards hibernate
这是我们关于休眠的 application.properties
# Username and password
spring.datasource.username = parkuser
spring.datasource.password = xxxxxxxxxxxxxxxxxxxxxx
spring.datasource.url= jdbc:mysql://xxxxxxxxxxxxxxxxxxxxxxxxx:3306/SMARTPARK?useSSL=false
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
spring.jpa.show-sql = false
# Hibernate ddl auto (create, create-drop, update): with "update" the database
# schema will be automatically updated accordingly to java entities found in
# the project
spring.jpa.hibernate.ddl-auto = update
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
In our pom.xml we have
在我们的 pom.xml 中,我们有
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<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>
<version>1.3.8.RELEASE</version>
</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-jdbc</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>
This is our StartServer.class
这是我们的 StartServer.class
@SpringBootApplication
@EnableScheduling
public class StartServer extends SpringBootServletInitializer{
public static void main(String[] args){
SpringApplication.run(StartServer.class, args);
}
@Bean
public HibernateJpaSessionFactoryBean sessionFactory() {
return new HibernateJpaSessionFactoryBean();
}
}
I cannot understand why the same jar works in a device and gives this error in another one and i cannot understand which is the error...
我不明白为什么同一个 jar 在一个设备中工作并在另一个设备中给出这个错误,我不明白哪个是错误......
回答by Thribhuvan Krishnamurthy
I ran into same problem. Then after cleaning my local maven repository the application was up and running. Clean your local maven repo (due to corrupted dependency) and try again!
我遇到了同样的问题。然后在清理我的本地 Maven 存储库后,应用程序启动并运行。清理您的本地 Maven 存储库(由于依赖关系已损坏)并重试!
回答by Kimchy
If in case you miss application.properties file in your project, then also you would face such issue. check its available in your classpath.
如果您错过了项目中的 application.properties 文件,那么您也会面临这样的问题。检查它在您的类路径中是否可用。
回答by Achille_vanhoutte
I'm not 100% sure but i would have replaced this :
我不是 100% 确定,但我会替换它:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
....
</dependency>
With this:
有了这个:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
...
</dependencies>
See thus example below :
请参见下面的示例:
<groupId>org.springframework</groupId>
<artifactId>gs-relational-data-access</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<properties>
....
</properties>
<dependencies>
<dependency>
....
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>[5,]</version>
</dependency>
</dependencies>
or else, just do this :
否则,就这样做:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>your version</version>
</dependency>