SpringBoot(7) SpringBoot启动方式
第一种启动方式:对含有main方法的类进行 Run As Java Application
第二种方式:对项目“Maven Install” 生成jar包 在target目录下(java -jar xxxx.jar)
在pom中添加maven插件:
1 <build> 2 <plugins> 3 <plugin> 4 <groupId>org.springframework.boot</groupId> 5 <artifactId>spring-boot-maven-plugin</artifactId> 6 </plugin> 7 </plugins> 8 </build>
如果没有加,则执行jar包 ,报错如下
java -jar spring-boot-demo-0.0.1-SNAPSHOT.jar no main manifest attribute, in spring-boot-demo-0.0.1-SNAPSHOT.jar
1 项目结构 2 example.jar 3 | 4 +-META-INF 5 | +-MANIFEST.MF 6 +-org 7 | +-springframework 8 | +-boot 9 | +-loader 10 | +-<spring boot loader classes> 11 +-BOOT-INF 12 +-classes 13 | +-mycompany 14 | +-project 15 | +-YourClasses.class 16 +-lib 17 +-dependency1.jar 18 +-dependency2.jar
目录结构讲解,官网:https://docs.spring.io/spring-boot/docs/2.1.0.BUILD-SNAPSHOT/reference/htmlsingle/#executable-jar-jar-file-structure
第三种方式:war包方式启动
步骤1:
在pom.xml中将打包形式 jar 修改为war <packaging>war</packaging>
构建项目名称 <finalName>xdclass_springboot</finalName>
步骤2:修改启动类
1 @SpringBootApplication 2 public class XdclassApplication extends SpringBootServletInitializer { 3 4 @Override 5 protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 6 return application.sources(XdclassApplication.class); 7 } 8 9 public static void main(String[] args) throws Exception { 10 SpringApplication.run(XdclassApplication.class, args); 11 } 12 13 }
步骤3:maven install后,将打包出来的war包放在tomcat下,启动tomcat