日志
Connected to the target VM, address: '127.0.0.1:65352', transport: 'socket'
test NotificationServiceApplication static log
DEBUG StatusLogger org.slf4j.helpers.Log4jLoggerFactory is not on classpath. Good!
DEBUG . [07-10-2019 17:30:22:264] [main] [project-service,,,] [o.s.b.c.l.ClasspathLoggingApplicationListener] Application started with classpath: [file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/charsets.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/deploy.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/access-bridge-64.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/cldrdata.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/dnsns.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/jaccess.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/jfxrt.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/localedata.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/nashorn.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/sunec.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/sunjce_provider.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/sunmscapi.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/sunpkcs11.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/zipfs.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/javaws.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/jce.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/jfr.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/jfxswt.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/jsse.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/management-agent.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/plugin.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/resources.jar, file:/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/rt.jar, file:/D:/real-repo/project-service/project-service/target/classes/, file:/C:/Users/UserName/.m2/repository/org/springframework/boot/spring-boot-starter-actuator/2.0.4.RELEASE/spring-boot-starter-actuator-2.0.4.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/boot/spring-boot-starter/2.0.4.RELEASE/spring-boot-starter-2.0.4.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/boot/spring-boot/2.0.4.RELEASE/spring-boot-2.0.4.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.0.4.RELEASE/spring-boot-autoconfigure-2.0.4.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/boot/spring-boot-starter-logging/2.0.4.RELEASE/spring-boot-starter-logging-2.0.4.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar, file:/C:/Users/UserName/.m2/repository/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar, file:/C:/Users/UserName/.m2/repository/org/apache/logging/log4j/log4j-to-slf4j/2.10.0/log4j-to-slf4j-2.10.0.jar, file:/C:/Users/UserName/.m2/repository/org/apache/logging/log4j/log4j-api/2.10.0/log4j-api-2.10.0.jar, file:/C:/Users/UserName/.m2/repository/org/slf4j/jul-to-slf4j/1.7.25/jul-to-slf4j-1.7.25.jar, file:/C:/Users/UserName/.m2/repository/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar, file:/C:/Users/UserName/.m2/repository/org/yaml/snakeyaml/1.19/snakeyaml-1.19.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/boot/spring-boot-actuator-autoconfigure/2.0.4.RELEASE/spring-boot-actuator-autoconfigure-2.0.4.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/boot/spring-boot-actuator/2.0.4.RELEASE/spring-boot-actuator-2.0.4.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.9.6/jackson-databind-2.9.6.jar, file:/C:/Users/UserName/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.9.6/jackson-core-2.9.6.jar, file:/C:/Users/UserName/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.9.6/jackson-datatype-jsr310-2.9.6.jar, file:/C:/Users/UserName/.m2/repository/io/micrometer/micrometer-core/1.0.6/micrometer-core-1.0.6.jar, file:/C:/Users/UserName/.m2/repository/org/hdrhistogram/HdrHistogram/2.1.10/HdrHistogram-2.1.10.jar, file:/C:/Users/UserName/.m2/repository/org/latencyutils/LatencyUtils/2.0.3/LatencyUtils-2.0.3.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/boot/spring-boot-starter-web/2.0.4.RELEASE/spring-boot-starter-web-2.0.4.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/boot/spring-boot-starter-json/2.0.4.RELEASE/spring-boot-starter-json-2.0.4.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.9.6/jackson-datatype-jdk8-2.9.6.jar, file:/C:/Users/UserName/.m2/repository/com/fasterxml/jackson/module/jackson-module-parameter-names/2.9.6/jackson-module-parameter-names-2.9.6.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/2.0.4.RELEASE/spring-boot-starter-tomcat-2.0.4.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.32/tomcat-embed-core-8.5.32.jar, file:/C:/Users/UserName/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/8.5.32/tomcat-embed-el-8.5.32.jar, file:/C:/Users/UserName/.m2/repository/org/apache/tomcat/embed/tomcat-embed-websocket/8.5.32/tomcat-embed-websocket-8.5.32.jar, file:/C:/Users/UserName/.m2/repository/org/hibernate/validator/hibernate-validator/6.0.11.Final/hibernate-validator-6.0.11.Final.jar, file:/C:/Users/UserName/.m2/repository/javax/validation/validation-api/2.0.1.Final/validation-api-2.0.1.Final.jar, file:/C:/Users/UserName/.m2/repository/org/jboss/logging/jboss-logging/3.3.2.Final/jboss-logging-3.3.2.Final.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/spring-web/5.0.8.RELEASE/spring-web-5.0.8.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/spring-webmvc/5.0.8.RELEASE/spring-webmvc-5.0.8.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/spring-aop/5.0.8.RELEASE/spring-aop-5.0.8.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/spring-expression/5.0.8.RELEASE/spring-expression-5.0.8.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/boot/spring-boot-starter-web-services/2.0.4.RELEASE/spring-boot-starter-web-services-2.0.4.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/spring-oxm/5.0.8.RELEASE/spring-oxm-5.0.8.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/ws/spring-ws-core/3.0.3.RELEASE/spring-ws-core-3.0.3.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/ws/spring-xml/3.0.3.RELEASE/spring-xml-3.0.3.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/commons-io/commons-io/2.5/commons-io-2.5.jar, file:/C:/Users/UserName/.m2/repository/io/springfox/springfox-swagger2/2.7.0/springfox-swagger2-2.7.0.jar, file:/C:/Users/UserName/.m2/repository/io/swagger/swagger-annotations/1.5.13/swagger-annotations-1.5.13.jar, file:/C:/Users/UserName/.m2/repository/io/swagger/swagger-models/1.5.13/swagger-models-1.5.13.jar, file:/C:/Users/UserName/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.9.0/jackson-annotations-2.9.0.jar, file:/C:/Users/UserName/.m2/repository/io/springfox/springfox-spi/2.7.0/springfox-spi-2.7.0.jar, file:/C:/Users/UserName/.m2/repository/io/springfox/springfox-core/2.7.0/springfox-core-2.7.0.jar, file:/C:/Users/UserName/.m2/repository/io/springfox/springfox-schema/2.7.0/springfox-schema-2.7.0.jar, file:/C:/Users/UserName/.m2/repository/io/springfox/springfox-swagger-common/2.7.0/springfox-swagger-common-2.7.0.jar, file:/C:/Users/UserName/.m2/repository/io/springfox/springfox-spring-web/2.7.0/springfox-spring-web-2.7.0.jar, file:/C:/Users/UserName/.m2/repository/org/reflections/reflections/0.9.11/reflections-0.9.11.jar, file:/C:/Users/UserName/.m2/repository/com/google/guava/guava/18.0/guava-18.0.jar, file:/C:/Users/UserName/.m2/repository/com/fasterxml/classmate/1.3.4/classmate-1.3.4.jar, file:/C:/Users/UserName/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/plugin/spring-plugin-metadata/1.2.0.RELEASE/spring-plugin-metadata-1.2.0.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/mapstruct/mapstruct/1.1.0.Final/mapstruct-1.1.0.Final.jar, file:/C:/Users/UserName/.m2/repository/io/springfox/springfox-swagger-ui/2.7.0/springfox-swagger-ui-2.7.0.jar, file:/C:/Users/UserName/.m2/repository/pl/pojo/pojo-tester/0.7.6/pojo-tester-0.7.6.jar, file:/C:/Users/UserName/.m2/repository/org/apache/commons/commons-collections4/4.1/commons-collections4-4.1.jar, file:/C:/Users/UserName/.m2/repository/com/googlecode/combinatoricslib/combinatoricslib/2.1/combinatoricslib-2.1.jar, file:/C:/Users/UserName/.m2/repository/org/javassist/javassist/3.22.0-GA/javassist-3.22.0-GA.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/cloud/spring-cloud-commons/2.0.0.RELEASE/spring-cloud-commons-2.0.0.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/security/spring-security-crypto/5.0.7.RELEASE/spring-security-crypto-5.0.7.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/cloud/spring-cloud-context/2.0.0.RELEASE/spring-cloud-context-2.0.0.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/security/oauth/spring-security-oauth2/2.3.3.RELEASE/spring-security-oauth2-2.3.3.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/spring-beans/5.0.8.RELEASE/spring-beans-5.0.8.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/spring-core/5.0.8.RELEASE/spring-core-5.0.8.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/spring-jcl/5.0.8.RELEASE/spring-jcl-5.0.8.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/spring-context/5.0.8.RELEASE/spring-context-5.0.8.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/security/spring-security-core/5.0.7.RELEASE/spring-security-core-5.0.7.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/security/spring-security-config/5.0.7.RELEASE/spring-security-config-5.0.7.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/security/spring-security-web/5.0.7.RELEASE/spring-security-web-5.0.7.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/commons-codec/commons-codec/1.11/commons-codec-1.11.jar, file:/C:/Users/UserName/.m2/repository/org/codehaus/jackson/jackson-mapper-asl/1.9.13/jackson-mapper-asl-1.9.13.jar, file:/C:/Users/UserName/.m2/repository/org/codehaus/jackson/jackson-core-asl/1.9.13/jackson-core-asl-1.9.13.jar, file:/C:/Users/UserName/.m2/repository/net/bytebuddy/byte-buddy/1.7.11/byte-buddy-1.7.11.jar, file:/C:/Users/UserName/.m2/repository/org/flywaydb/flyway-core/5.0.7/flyway-core-5.0.7.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/boot/spring-boot-starter-data-jpa/2.0.4.RELEASE/spring-boot-starter-data-jpa-2.0.4.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/boot/spring-boot-starter-aop/2.0.4.RELEASE/spring-boot-starter-aop-2.0.4.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/aspectj/aspectjweaver/1.8.13/aspectjweaver-1.8.13.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/boot/spring-boot-starter-jdbc/2.0.4.RELEASE/spring-boot-starter-jdbc-2.0.4.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/com/zaxxer/HikariCP/2.7.9/HikariCP-2.7.9.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/spring-jdbc/5.0.8.RELEASE/spring-jdbc-5.0.8.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/hibernate/hibernate-core/5.2.17.Final/hibernate-core-5.2.17.Final.jar, file:/C:/Users/UserName/.m2/repository/org/hibernate/javax/persistence/hibernate-jpa-2.1-api/1.0.2.Final/hibernate-jpa-2.1-api-1.0.2.Final.jar, file:/C:/Users/UserName/.m2/repository/antlr/antlr/2.7.7/antlr-2.7.7.jar, file:/C:/Users/UserName/.m2/repository/org/jboss/jandex/2.0.3.Final/jandex-2.0.3.Final.jar, file:/C:/Users/UserName/.m2/repository/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar, file:/C:/Users/UserName/.m2/repository/org/hibernate/common/hibernate-commons-annotations/5.0.1.Final/hibernate-commons-annotations-5.0.1.Final.jar, file:/C:/Users/UserName/.m2/repository/javax/transaction/javax.transaction-api/1.2/javax.transaction-api-1.2.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/data/spring-data-jpa/2.0.9.RELEASE/spring-data-jpa-2.0.9.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/data/spring-data-commons/2.0.9.RELEASE/spring-data-commons-2.0.9.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/spring-orm/5.0.8.RELEASE/spring-orm-5.0.8.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/spring-tx/5.0.8.RELEASE/spring-tx-5.0.8.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/spring-aspects/5.0.8.RELEASE/spring-aspects-5.0.8.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/com/microsoft/sqlserver/mssql-jdbc/6.2.2.jre8/mssql-jdbc-6.2.2.jre8.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/cloud/spring-cloud-starter-sleuth/2.0.0.RELEASE/spring-cloud-starter-sleuth-2.0.0.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/cloud/spring-cloud-starter/2.0.0.RELEASE/spring-cloud-starter-2.0.0.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/security/spring-security-rsa/1.0.5.RELEASE/spring-security-rsa-1.0.5.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/bouncycastle/bcpkix-jdk15on/1.56/bcpkix-jdk15on-1.56.jar, file:/C:/Users/UserName/.m2/repository/org/bouncycastle/bcprov-jdk15on/1.56/bcprov-jdk15on-1.56.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/cloud/spring-cloud-sleuth-core/2.0.0.RELEASE/spring-cloud-sleuth-core-2.0.0.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/aspectj/aspectjrt/1.8.13/aspectjrt-1.8.13.jar, file:/C:/Users/UserName/.m2/repository/io/zipkin/brave/brave/5.1.0/brave-5.1.0.jar, file:/C:/Users/UserName/.m2/repository/io/zipkin/zipkin2/zipkin/2.9.3/zipkin-2.9.3.jar, file:/C:/Users/UserName/.m2/repository/io/zipkin/reporter2/zipkin-reporter/2.7.3/zipkin-reporter-2.7.3.jar, file:/C:/Users/UserName/.m2/repository/io/zipkin/brave/brave-context-log4j2/5.1.0/brave-context-log4j2-5.1.0.jar, file:/C:/Users/UserName/.m2/repository/io/zipkin/brave/brave-instrumentation-spring-web/5.1.0/brave-instrumentation-spring-web-5.1.0.jar, file:/C:/Users/UserName/.m2/repository/io/zipkin/brave/brave-instrumentation-http/5.1.0/brave-instrumentation-http-5.1.0.jar, file:/C:/Users/UserName/.m2/repository/io/zipkin/brave/brave-instrumentation-spring-rabbit/5.1.0/brave-instrumentation-spring-rabbit-5.1.0.jar, file:/C:/Users/UserName/.m2/repository/io/zipkin/brave/brave-instrumentation-kafka-clients/5.1.0/brave-instrumentation-kafka-clients-5.1.0.jar, file:/C:/Users/UserName/.m2/repository/io/zipkin/brave/brave-instrumentation-httpclient/5.1.0/brave-instrumentation-httpclient-5.1.0.jar, file:/C:/Users/UserName/.m2/repository/io/zipkin/brave/brave-instrumentation-httpasyncclient/5.1.0/brave-instrumentation-httpasyncclient-5.1.0.jar, file:/C:/Users/UserName/.m2/repository/io/zipkin/brave/brave-instrumentation-spring-webmvc/5.1.0/brave-instrumentation-spring-webmvc-5.1.0.jar, file:/C:/Users/UserName/.m2/repository/io/zipkin/brave/brave-instrumentation-servlet/5.1.0/brave-instrumentation-servlet-5.1.0.jar, file:/C:/Users/UserName/.m2/repository/org/apache/httpcomponents/httpclient/4.5.6/httpclient-4.5.6.jar, file:/C:/Users/UserName/.m2/repository/org/apache/httpcomponents/httpcore/4.4.10/httpcore-4.4.10.jar, file:/C:/Users/UserName/.m2/repository/com/companyname/common/common-service-util/1.0.0/common-service-util-1.0.0.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/cloud/spring-cloud-starter-oauth2/2.0.0.RELEASE/spring-cloud-starter-oauth2-2.0.0.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/cloud/spring-cloud-starter-security/2.0.0.RELEASE/spring-cloud-starter-security-2.0.0.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/cloud/spring-cloud-security/2.0.0.RELEASE/spring-cloud-security-2.0.0.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/boot/spring-boot-starter-security/2.0.4.RELEASE/spring-boot-starter-security-2.0.4.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/security/oauth/boot/spring-security-oauth2-autoconfigure/2.0.0.RELEASE/spring-security-oauth2-autoconfigure-2.0.0.RELEASE.jar, file:/C:/Users/UserName/.m2/repository/org/springframework/security/spring-security-jwt/1.0.9.RELEASE/spring-security-jwt-1.0.9.RELEASE.jar, file:/C:/Program%20Files/JetBrains/IntelliJ%20IDEA%20Community%20Edition%202018.3.6/lib/idea_rt.jar, file:/C:/Users/UserName/.IdeaIC2018.3/system/captureAgent/debugger-agent.jar]
扯犊子
先看一下启动类
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
@ComponentScan(basePackages = { "com.companyname.*" })
@EnableJpaRepositories("com.companyname.hk.notification.repository")
@EnableTransactionManagement
public class NotificationServiceApplication {
static {
System.out.println("test NotificationServiceApplication static log");
}
public static void main(String[] args) throws Exception {
SpringApplication.run(NotificationServiceApplication.class, args);
}
}
main方法作程序的入口,可以看是jvm虚拟机第一行执行的命令。这里我加了一个static代码块。实际上在debug模式下,会先于static打印日志。打印出一条日志信息:
Connected to the target VM, address: '127.0.0.1:65352', transport: 'socket'
这是windows环境下采用内存共享模式来debug。可惜日志前面没有类名。我找不到打印这个日志的类。
不过日志已经说得很明确了,是客户端的代码要连接java虚拟机,以打印日志。
接着打印了static代码块的日志:
test NotificationServiceApplication static log
然后执行代码:
SpringApplication.run(NotificationServiceApplication.class, args);
可以看到,这个run方法是一个static方法。在类初始化的时候,虽然调用类的static方法,但是SpringApplication的初始化还没有完成,他需要去初始化他的static成员变量。
/**
* Static helper that can be used to run a {@link SpringApplication} from the
* specified source using default settings.
* @param primarySource the primary source to load
* @param args the application arguments (usually passed from a Java main method)
* @return the running {@link ApplicationContext}
*/
public static ConfigurableApplicationContext run(Class<?> primarySource,
String... args) {
return run(new Class<?>[] { primarySource }, args);
}
也就是说,他会先按照顺序去实例化SpringApplication的static变量。代码如下:
/**
* The class name of application context that will be used by default for non-web
* environments.
*/
public static final String DEFAULT_CONTEXT_CLASS = "org.springframework.context."
+ "annotation.AnnotationConfigApplicationContext";
/**
* The class name of application context that will be used by default for web
* environments.
*/
public static final String DEFAULT_WEB_CONTEXT_CLASS = "org.springframework.boot."
+ "web.servlet.context.AnnotationConfigServletWebServerApplicationContext";
private static final String[] WEB_ENVIRONMENT_CLASSES = { "javax.servlet.Servlet",
"org.springframework.web.context.ConfigurableWebApplicationContext" };
/**
* The class name of application context that will be used by default for reactive web
* environments.
*/
public static final String DEFAULT_REACTIVE_WEB_CONTEXT_CLASS = "org.springframework."
+ "boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext";
private static final String REACTIVE_WEB_ENVIRONMENT_CLASS = "org.springframework."
+ "web.reactive.DispatcherHandler";
private static final String MVC_WEB_ENVIRONMENT_CLASS = "org.springframework."
+ "web.servlet.DispatcherServlet";
private static final String JERSEY_WEB_ENVIRONMENT_CLASS = "org.glassfish.jersey.server.ResourceConfig";
/**
* Default banner location.
*/
public static final String BANNER_LOCATION_PROPERTY_VALUE = SpringApplicationBannerPrinter.DEFAULT_BANNER_LOCATION;
/**
* Banner location property key.
*/
public static final String BANNER_LOCATION_PROPERTY = SpringApplicationBannerPrinter.BANNER_LOCATION_PROPERTY;
private static final String SYSTEM_PROPERTY_JAVA_AWT_HEADLESS = "java.awt.headless";
private static final Log logger = LogFactory.getLog(SpringApplication.class);
需要注意的是, 我打了很多断点。发现对应String类型的static变量,是打不起断点的。只能打一个Java File watch point. 而不是Java Line watch point. 他直接走到了第170行。也就是说 String[] 类型的 static 变量。并且,即使第191行有应用到另一个类的String 类型的static 变量。但是也不会走到另一个类SpringApplicationBannerPrinter中去初始化他的static变量。感觉这一块编译器有优化?
看一下SpringApplication的文档吧
可用于从 Java 主方法引导和启动 Spring 应用程序的类。默认情况下,类将执行以下步骤来引导应用序:
- 创建适当的应用程序上下文(ApplicationContext)实例(取决于您的类路径)
- 注册 CommandLinePropertySource 以为 Spring properties 公开命令行参数
- 刷新这个应用程序上下文,加载所有的单例beans
- 触发任何 CommandLineRunner beans.
仔细看一下日志设置
代码在SpringApplication类的200行
// at line 200.
private static final Log logger = LogFactory.getLog(SpringApplication.class);
title SpringBoot log setting
SpringApplication->LogFactory:getLog(SpringApplication.class);
LogFactory->LogFactory.Log4jDelegate:createLog("org.springframework.boot.SpringApplication")
LogFactory.Log4jDelegate->LogFactory.Log4jLog:new Log4jLog("org.springframework.boot.SpringApplication")
LogFactory.Log4jLog->LogFactory.Log4jLog:set static String FQCN = "org.apache.commons.logging.LogFactory$Log4jLog"
note left of LogFactory.Log4jLog
execute private static final LoggerContext loggerContext =
LogManager.getContext(Log4jLog.class.getClassLoader(), false);
Log4jLog.class.getClassLoader() return "sun.misc.Launcher$AppClassLoader"
LogFactory.Log4jLog->LogManager.getContext("sun.misc.Launcher$AppClassLoader", false)
end note
其实还有更细节的调用,我没有全写出来。