使用mvn spring-boot:run可以正常启动
但是通过main方法(即intellij IDEA的小三角启动)
进程会直接关掉:
log信息如下:
:: Spring Boot :: (v1.4.2.RELEASE)
2016-12-22 14:31:56.663 INFO 6525 --- [ main] c.t.SpringbootMybatisApplication : Starting SpringbootMybatisApplication on lijiechudeMacBook-Pro.local with PID 6525 (/Users/lijiechu/Documents/playonthecloud-backend/target/classes started by lijiechu in /Users/lijiechu/Documents/playonthecloud-backend)
2016-12-22 14:31:56.665 INFO 6525 --- [ main] c.t.SpringbootMybatisApplication : No active profile set, falling back to default profiles: default
2016-12-22 14:31:56.714 INFO 6525 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@243c4f91: startup date [Thu Dec 22 14:31:56 CST 2016]; root of context hierarchy
2016-12-22 14:31:57.867 INFO 6525 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-12-22 14:31:57.878 INFO 6525 --- [ main] c.t.SpringbootMybatisApplication : Started SpringbootMybatisApplication in 2.076 seconds (JVM running for 2.403)
2016-12-22 14:31:57.879 INFO 6525 --- [ Thread-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@243c4f91: startup date [Thu Dec 22 14:31:56 CST 2016]; root of context hierarchy
2016-12-22 14:31:57.880 INFO 6525 --- [ Thread-1] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
Process finished with exit code 0
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.tongji409</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>springboot-mybatis</name>
<description>Intergrated Spring-Boot Framework with mybatis</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.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.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--alibaba fastjson-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.41</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
同时也配置了以下这个类:
package com.tongji409;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringbootMybatisApplication.class);
}
}
main方法的类上有个注解!注解!