Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why spring boot always shutdown in two hours

i build it using mvn clean package and get a xxx.jar file. run $java -jar xxx.jar >> output.log & start it, and it works well.

but about two hours later, it shutdown, why? here is an answer but don't work for me >>https://stackoverflow.com/a/22409655/1767024

here is my output.log:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.1.9.RELEASE)

2016-03-17 17:41:54.784  INFO 20016 --- [           main] com.hello.bibi.App                 : Starting App on iZ947723zxnZ with PID 20016 (/root/projects/taomi-back/bibi-0.0.1-SNAPSHOT.jar started by root in /root/projects/taomi-back)
2016-03-17 17:41:54.850  INFO 20016 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5cf0ac6e: startup date [Thu Mar 17 17:41:54 CST 2016]; root of context hierarchy
2016-03-17 17:41:56.477  INFO 20016 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'beanNameViewResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false;factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
2016-03-17 17:41:57.557  INFO 20016 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'databaseConfig4Bibi' of type [class com.hello.bibi.config.DatabaseConfig4Bibi$$EnhancerBySpringCGLIB$$5c20f114] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:58.434  INFO 20016 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'dataSource4bibi' of type [class com.jolbox.bonecp.BoneCPDataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.194  INFO 20016 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'sqlSessionFactory4bibi' of type [class org.apache.ibatis.session.defaults.DefaultSqlSessionFactory] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.278  INFO 20016 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'spiderJdCommentIncrMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.287  INFO 20016 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'spiderJdCommentMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.294  INFO 20016 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'spiderJdItemMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.300  INFO 20016 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'userMapper' of type [class org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.402  INFO 20016 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$364a7a87] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.436  INFO 20016 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'transactionAttributeSource' of type [class org.springframework.transaction.annotation.AnnotationTransactionAttributeSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.452  INFO 20016 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'transactionInterceptor' of type [class org.springframework.transaction.interceptor.TransactionInterceptor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.461  INFO 20016 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.config.internalTransactionAdvisor' of type [class org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-17 17:41:59.992  INFO 20016 --- [           main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 8090
2016-03-17 17:42:00.261  INFO 20016 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2016-03-17 17:42:00.263  INFO 20016 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/7.0.56
2016-03-17 17:42:00.420  INFO 20016 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2016-03-17 17:42:00.420  INFO 20016 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 5574 ms
2016-03-17 17:42:01.119  INFO 20016 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
2016-03-17 17:42:01.124  INFO 20016 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-03-17 17:42:01.519  INFO 20016 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2016-03-17 17:42:01.534  INFO 20016 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2016-03-17 17:42:01.648  INFO 20016 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {4.3.7.Final}
2016-03-17 17:42:01.651  INFO 20016 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2016-03-17 17:42:01.653  INFO 20016 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2016-03-17 17:42:01.991  INFO 20016 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2016-03-17 17:42:02.076  INFO 20016 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2016-03-17 17:42:02.155  INFO 20016 --- [           main] o.h.h.i.ast.ASTQueryTranslatorFactory    : HHH000397: Using ASTQueryTranslatorFactory
2016-03-17 17:42:02.534  INFO 20016 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-03-17 17:42:02.986  INFO 20016 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/bibi/commentIncrTop],methods=[],params=[],headers=[],consumes=[],produces=[application/json;charset=UTF-8],custom=[]}" onto public java.lang.String com.hello.bibi.controller.BibiController.commentIncrTop(javax.servlet.http.HttpServletRequest,int,int)
2016-03-17 17:42:02.986  INFO 20016 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/bibi/priceReduce],methods=[],params=[],headers=[],consumes=[],produces=[application/json;charset=UTF-8],custom=[]}" onto public java.lang.String com.hello.bibi.controller.BibiController.priceReduce(javax.servlet.http.HttpServletRequest,int,int)
2016-03-17 17:42:02.987  INFO 20016 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/bibi/categoryTree],methods=[],params=[],headers=[],consumes=[],produces=[application/json;charset=UTF-8],custom=[]}" onto public java.lang.String com.hello.bibi.controller.BibiController.categoryTree(javax.servlet.http.HttpServletRequest)
2016-03-17 17:42:02.992  INFO 20016 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/taomi/collect],methods=[GET],params=[],headers=[],consumes=[],produces=[application/json;charset=UTF-8],custom=[]}" onto public void com.hello.bibi.controller.CollectController.itemInfo(java.lang.String,java.lang.String,java.lang.String)
2016-03-17 17:42:02.994  INFO 20016 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[//testpage],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.hello.bibi.controller.HelloWorldController.helloWorld()
2016-03-17 17:42:02.994  INFO 20016 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[//test],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.hello.bibi.controller.HelloWorldController.helloWorld2(java.lang.String,int)
2016-03-17 17:42:02.994  INFO 20016 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[//test2/{id}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.hello.bibi.controller.HelloWorldController.test2(long)
2016-03-17 17:42:02.994  INFO 20016 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[//test3/{str}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.hello.bibi.controller.HelloWorldController.test3(java.lang.String)
2016-03-17 17:42:02.994  INFO 20016 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[//test4],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.hello.bibi.controller.HelloWorldController.test4(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-03-17 17:42:02.995  INFO 20016 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[//test5/{id}/vv/{str}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.hello.bibi.controller.HelloWorldController.test5(java.lang.String,java.lang.String)
2016-03-17 17:42:02.995  INFO 20016 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[//user],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.hello.bibi.controller.HelloWorldController.user()
2016-03-17 17:42:02.995  INFO 20016 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/user/test],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.hello.bibi.controller.UserController.isNameExist(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-03-17 17:42:02.998  INFO 20016 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[text/html],custom=[]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
2016-03-17 17:42:02.998  INFO 20016 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-03-17 17:42:03.043  INFO 20016 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-03-17 17:42:03.043  INFO 20016 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-03-17 17:42:03.526  INFO 20016 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2016-03-17 17:42:03.528  INFO 20016 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'dataSource4bibi' has been autodetected for JMX exposure
2016-03-17 17:42:03.532  INFO 20016 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located MBean 'dataSource4bibi': registering with JMX server as MBean [com.jolbox.bonecp:name=dataSource4bibi,type=BoneCPDataSource]
2016-03-17 17:42:03.729  INFO 20016 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8090/http
2016-03-17 17:42:03.731  INFO 20016 --- [           main] com.hello.bibi.App                 : Started App in 10.01 seconds (JVM running for 10.872)
2016-03-17 17:42:04.217  INFO 20016 --- [nio-8090-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2016-03-17 17:42:04.217  INFO 20016 --- [nio-8090-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2016-03-17 17:42:04.243  INFO 20016 --- [nio-8090-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 26 ms
2016-03-17 20:01:59.081  INFO 20016 --- [       Thread-2] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5cf0ac6e: startup date [Thu Mar 17 17:41:54 CST 2016]; root of context hierarchy
2016-03-17 20:01:59.085  INFO 20016 --- [       Thread-2] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown
2016-03-17 20:01:59.090  INFO 20016 --- [       Thread-2] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2016-03-17 20:01:59.092  INFO 20016 --- [       Thread-2] com.jolbox.bonecp.BoneCP                 : Shutting down connection pool...
2016-03-17 20:01:59.101  INFO 20016 --- [       Thread-2] com.jolbox.bonecp.BoneCP                 : Connection pool has been shutdown.

App.java

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class App {
    public static void main( String[] args ) {
        SpringApplication.run(App.class);
    }
}

pom.xml

<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.hello.bibi</groupId>
    <artifactId>bibi</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>bibi</name>
    <url>http://maven.apache.org</url>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.1.9.RELEASE</version>
    </parent>

    <properties>
        <main.basedir>${basedir}/../..</main.basedir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <mybatis.version>3.2.2</mybatis.version>
        <mybatisspring.version>1.2.0</mybatisspring.version>
        <app.mainClass>com.hello.bibi.App</app.mainClass>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>${mybatis.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>${mybatisspring.version}</version>
        </dependency>
        <dependency>
            <groupId>com.jolbox</groupId>
            <artifactId>bonecp</artifactId>
            <version>0.8.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>${app.mainClass}</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
like image 815
jychan Avatar asked Feb 08 '23 11:02

jychan


1 Answers

Run your application as follows instead:

nohup java -jar xxx.jar > output.log 2>&1&

From Wikipedia:

nohup is a POSIX command to ignore the HUP (hangup) signal. The HUP signal is, by convention, the way a terminal warns dependent processes of logout. Output that would normally go to the terminal goes to a file called nohup.out if it has not already been redirected.

From the Linux man pages:

nohup - run a command immune to hangups, with output to a non-tty

Furthermore, if you are only adding the web server to keep your application alive and do not actually use it, consider using a CountDownLatch instead:

@Bean
public CountDownLatch closeLatch() {
    return new CountDownLatch(1);
}

public static void main(String... args) throws InterruptedException {
    ApplicationContext ctx = SpringApplication.run(MyApp.class, args); 

    final CountDownLatch closeLatch = ctx.getBean(CountDownLatch.class);
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            closeLatch.countDown();
        }
    }); 
    closeLatch.await();
}

Now to stop your application, you can look up the process ID and issue a kill command from the console:

kill <PID>
like image 157
Willy du Preez Avatar answered Feb 13 '23 22:02

Willy du Preez