内容简介:Spring Boot应用程序的主类是一个类,它包含一个启动Spring ApplicationContext的public static void main()方法:默认情况下,如果未明确指定主类,则Spring将在编译时在类路径中搜索,如果找不到或发现多个都无法启动。Spring的Jar包或War包的META-INF/MANIFEST.MF清单如下:
Spring Boot应用程序的主类是一个类,它包含一个启动Spring ApplicationContext的public static void main()方法:
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
. ....
}
}
默认情况下,如果未明确指定主类,则Spring将在编译时在类路径中搜索,如果找不到或发现多个都无法启动。
Spring的Jar包或War包的META-INF/MANIFEST.MF清单如下:
Manifest-Version: 1.0 Start-Class: com.example.MyApplication Main-Class: org.springframework.boot.loader.JarLauncher
我们需要在清单中定义Start-Class属性,由JarLauncher或WarLauncher认识它以启动应用。也就是说,我们只有控制定义Start-Class属性才能控制Spring boot的入口。
如何使用Maven控制这个属性?
可以在pom.xml的属性部分中定义为start-class元素:
<properties>
<!-- The main class to start by executing "java -jar" -->
<start-class>com.example.MyApplication</start-class>
</properties>
请注意,只有在我们的pom.xml 中将spring-boot-starter-parent添加为<parent>时, 才能使用此属性。
可以将主类定义为pom.xml的plugin中的spring-boot-maven-plugin的mainClass元素 :
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.example.MyApplication</mainClass>
</configuration>
</plugin>
</plugins>
</build>
还可以通过命令行界面指定主类:
java -cp bootApp.jar -Dloader.main=com.example.MyApplication org.springframework.boot.loader.PropertiesLauncher
[该贴被banq于2018-08-25 12:27修改过]
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Android 源码设计模式解析与实战
何红辉、关爱民 / 人民邮电出版社 / 2015-11 / 79.00元
本书专门介绍Android源代码的设计模式,共26章,主要讲解面向对象的六大原则、主流的设计模式以及MVC和MVP模式。主要内容为:优化代码的首步、开闭原则、里氏替换原则、依赖倒置原则、接口隔离原则、迪米特原则、单例模式、Builder模式、原型模式、工厂方法模式、抽象工厂模式、策略模式、状态模式、责任链模式、解释器模式、命令模式、观察者模式、备忘录模式、迭代器模式、模板方法模式、访问者模式、中介......一起来看看 《Android 源码设计模式解析与实战》 这本书的介绍吧!