D:\softs\java\jdk11\bin\java.exe -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -javaagent:D:\softs\idea\IDEA20183\lib\idea_rt.jar=60107:D:\softs\idea\IDEA20183\bin -Dfile.encoding=UTF-8 -classpath D:\files\ideaspace\spring-source-code-analysis\target\classes;D:\files\repo\org\springframework\boot\spring-boot-starter-web\2.2.0.RELEASE\spring-boot-starter-web-2.2.0.RELEASE.jar;D:\files\repo\org\springframework\boot\spring-boot-starter\2.2.0.RELEASE\spring-boot-starter-2.2.0.RELEASE.jar;D:\files\repo\org\springframework\boot\spring-boot-starter-logging\2.2.0.RELEASE\spring-boot-starter-logging-2.2.0.RELEASE.jar;D:\files\repo\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\files\repo\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\files\repo\org\apache\logging\log4j\log4j-to-slf4j\2.12.1\log4j-to-slf4j-2.12.1.jar;D:\files\repo\org\apache\logging\log4j\log4j-api\2.12.1\log4j-api-2.12.1.jar;D:\files\repo\org\slf4j\jul-to-slf4j\1.7.28\jul-to-slf4j-1.7.28.jar;D:\files\repo\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;D:\files\repo\org\yaml\snakeyaml\1.25\snakeyaml-1.25.jar;D:\files\repo\org\springframework\boot\spring-boot-starter-json\2.2.0.RELEASE\spring-boot-starter-json-2.2.0.RELEASE.jar;D:\files\repo\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.10.0\jackson-datatype-jdk8-2.10.0.jar;D:\files\repo\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.10.0\jackson-datatype-jsr310-2.10.0.jar;D:\files\repo\com\fasterxml\jackson\module\jackson-module-parameter-names\2.10.0\jackson-module-parameter-names-2.10.0.jar;D:\files\repo\org\springframework\boot\spring-boot-starter-tomcat\2.2.0.RELEASE\spring-boot-starter-tomcat-2.2.0.RELEASE.jar;D:\files\repo\org\apache\tomcat\embed\tomcat-embed-core\9.0.27\tomcat-embed-core-9.0.27.jar;D:\files\repo\org\apache\tomcat\embed\tomcat-embed-el\9.0.27\tomcat-embed-el-9.0.27.jar;D:\files\repo\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.27\tomcat-embed-websocket-9.0.27.jar;D:\files\repo\org\springframework\boot\spring-boot-starter-validation\2.2.0.RELEASE\spring-boot-starter-validation-2.2.0.RELEASE.jar;D:\files\repo\jakarta\validation\jakarta.validation-api\2.0.1\jakarta.validation-api-2.0.1.jar;D:\files\repo\org\hibernate\validator\hibernate-validator\6.0.17.Final\hibernate-validator-6.0.17.Final.jar;D:\files\repo\org\jboss\logging\jboss-logging\3.4.1.Final\jboss-logging-3.4.1.Final.jar;D:\files\repo\com\fasterxml\classmate\1.5.0\classmate-1.5.0.jar;D:\files\repo\org\springframework\spring-web\5.2.0.RELEASE\spring-web-5.2.0.RELEASE.jar;D:\files\repo\org\springframework\boot\spring-boot-devtools\2.2.0.RELEASE\spring-boot-devtools-2.2.0.RELEASE.jar;D:\files\repo\org\springframework\boot\spring-boot\2.2.0.RELEASE\spring-boot-2.2.0.RELEASE.jar;D:\files\repo\org\springframework\boot\spring-boot-autoconfigure\2.2.0.RELEASE\spring-boot-autoconfigure-2.2.0.RELEASE.jar;D:\files\repo\mysql\mysql-connector-java\8.0.18\mysql-connector-java-8.0.18.jar;D:\files\repo\org\apache\commons\commons-lang3\3.3.2\commons-lang3-3.3.2.jar;D:\files\repo\org\projectlombok\lombok\1.18.10\lombok-1.18.10.jar;D:\files\repo\org\apache\dubbo\dubbo-common\2.7.5\dubbo-common-2.7.5.jar;D:\files\repo\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;D:\files\repo\log4j\log4j\1.2.16\log4j-1.2.16.jar;D:\files\repo\org\javassist\javassist\3.20.0-GA\javassist-3.20.0-GA.jar;D:\files\repo\commons-io\commons-io\2.6\commons-io-2.6.jar;D:\files\repo\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;D:\files\repo\org\springframework\spring-webmvc\5.2.12.RELEASE\spring-webmvc-5.2.12.RELEASE.jar;D:\files\repo\org\springframework\spring-aop\5.2.0.RELEASE\spring-aop-5.2.0.RELEASE.jar;D:\files\repo\org\springframework\spring-beans\5.2.0.RELEASE\spring-beans-5.2.0.RELEASE.jar;D:\files\repo\org\springframework\spring-context\5.2.0.RELEASE\spring-context-5.2.0.RELEASE.jar;D:\files\repo\org\springframework\spring-core\5.2.0.RELEASE\spring-core-5.2.0.RELEASE.jar;D:\files\repo\org\springframework\spring-jcl\5.2.0.RELEASE\spring-jcl-5.2.0.RELEASE.jar;D:\files\repo\org\springframework\spring-expression\5.2.0.RELEASE\spring-expression-5.2.0.RELEASE.jar;D:\files\repo\org\aspectj\aspectjweaver\1.9.4\aspectjweaver-1.9.4.jar;D:\files\repo\org\springframework\boot\spring-boot-starter-aop\2.2.0.RELEASE\spring-boot-starter-aop-2.2.0.RELEASE.jar;D:\files\repo\com\alibaba\fastjson\1.2.68\fastjson-1.2.68.jar;D:\files\repo\io\netty\netty-all\4.1.69.Final\netty-all-4.1.69.Final.jar;D:\files\repo\io\netty\netty-buffer\4.1.42.Final\netty-buffer-4.1.42.Final.jar;D:\files\repo\io\netty\netty-codec\4.1.42.Final\netty-codec-4.1.42.Final.jar;D:\files\repo\io\netty\netty-codec-dns\4.1.42.Final\netty-codec-dns-4.1.42.Final.jar;D:\files\repo\io\netty\netty-codec-haproxy\4.1.42.Final\netty-codec-haproxy-4.1.42.Final.jar;D:\files\repo\io\netty\netty-codec-http\4.1.42.Final\netty-codec-http-4.1.42.Final.jar;D:\files\repo\io\netty\netty-codec-http2\4.1.42.Final\netty-codec-http2-4.1.42.Final.jar;D:\files\repo\io\netty\netty-codec-memcache\4.1.42.Final\netty-codec-memcache-4.1.42.Final.jar;D:\files\repo\io\netty\netty-codec-mqtt\4.1.42.Final\netty-codec-mqtt-4.1.42.Final.jar;D:\files\repo\io\netty\netty-codec-redis\4.1.42.Final\netty-codec-redis-4.1.42.Final.jar;D:\files\repo\io\netty\netty-codec-smtp\4.1.42.Final\netty-codec-smtp-4.1.42.Final.jar;D:\files\repo\io\netty\netty-codec-socks\4.1.42.Final\netty-codec-socks-4.1.42.Final.jar;D:\files\repo\io\netty\netty-codec-stomp\4.1.42.Final\netty-codec-stomp-4.1.42.Final.jar;D:\files\repo\io\netty\netty-codec-xml\4.1.42.Final\netty-codec-xml-4.1.42.Final.jar;D:\files\repo\com\fasterxml\aalto-xml\1.0.0\aalto-xml-1.0.0.jar;D:\files\repo\org\codehaus\woodstox\stax2-api\4.0.0\stax2-api-4.0.0.jar;D:\files\repo\io\netty\netty-common\4.1.42.Final\netty-common-4.1.42.Final.jar;D:\files\repo\io\netty\netty-handler\4.1.42.Final\netty-handler-4.1.42.Final.jar;D:\files\repo\io\netty\netty-handler-proxy\4.1.42.Final\netty-handler-proxy-4.1.42.Final.jar;D:\files\repo\io\netty\netty-resolver\4.1.42.Final\netty-resolver-4.1.42.Final.jar;D:\files\repo\io\netty\netty-resolver-dns\4.1.42.Final\netty-resolver-dns-4.1.42.Final.jar;D:\files\repo\io\netty\netty-transport\4.1.42.Final\netty-transport-4.1.42.Final.jar;D:\files\repo\io\netty\netty-transport-rxtx\4.1.42.Final\netty-transport-rxtx-4.1.42.Final.jar;D:\files\repo\org\rxtx\rxtx\2.1.7\rxtx-2.1.7.jar;D:\files\repo\io\netty\netty-transport-sctp\4.1.42.Final\netty-transport-sctp-4.1.42.Final.jar;D:\files\repo\io\netty\netty-transport-udt\4.1.42.Final\netty-transport-udt-4.1.42.Final.jar;D:\files\repo\com\barchart\udt\barchart-udt-bundle\2.3.0\barchart-udt-bundle-2.3.0.jar;D:\files\repo\io\netty\netty-transport-native-epoll\4.1.42.Final\netty-transport-native-epoll-4.1.42.Final.jar;D:\files\repo\io\netty\netty-transport-native-unix-common\4.1.42.Final\netty-transport-native-unix-common-4.1.42.Final.jar;D:\files\repo\io\netty\netty-transport-native-kqueue\4.1.42.Final\netty-transport-native-kqueue-4.1.42.Final.jar;D:\files\repo\io\netty\netty-resolver-dns-native-macos\4.1.69.Final\netty-resolver-dns-native-macos-4.1.69.Final.jar;D:\files\repo\io\netty\netty-transport-native-epoll\4.1.42.Final\netty-transport-native-epoll-4.1.42.Final-linux-x86_64.jar;D:\files\repo\io\netty\netty-transport-native-epoll\4.1.69.Final\netty-transport-native-epoll-4.1.69.Final-linux-aarch_64.jar;D:\files\repo\io\netty\netty-transport-native-kqueue\4.1.42.Final\netty-transport-native-kqueue-4.1.42.Final-osx-x86_64.jar;D:\files\repo\io\netty\netty-transport-native-kqueue\4.1.69.Final\netty-transport-native-kqueue-4.1.69.Final-osx-aarch_64.jar;D:\files\repo\io\netty\netty-resolver-dns-native-macos\4.1.69.Final\netty-resolver-dns-native-macos-4.1.69.Final-osx-x86_64.jar;D:\files\repo\io\netty\netty-resolver-dns-native-macos\4.1.69.Final\netty-resolver-dns-native-macos-4.1.69.Final-osx-aarch_64.jar;D:\files\repo\org\redisson\redisson\3.16.3\redisson-3.16.3.jar;D:\files\repo\javax\cache\cache-api\1.1.1\cache-api-1.1.1.jar;D:\files\repo\io\projectreactor\reactor-core\3.3.0.RELEASE\reactor-core-3.3.0.RELEASE.jar;D:\files\repo\org\reactivestreams\reactive-streams\1.0.3\reactive-streams-1.0.3.jar;D:\files\repo\io\reactivex\rxjava3\rxjava\3.0.12\rxjava-3.0.12.jar;D:\files\repo\org\jboss\marshalling\jboss-marshalling\2.0.11.Final\jboss-marshalling-2.0.11.Final.jar;D:\files\repo\org\jboss\marshalling\jboss-marshalling-river\2.0.11.Final\jboss-marshalling-river-2.0.11.Final.jar;D:\files\repo\org\slf4j\slf4j-api\1.7.28\slf4j-api-1.7.28.jar;D:\files\repo\com\fasterxml\jackson\core\jackson-annotations\2.10.0\jackson-annotations-2.10.0.jar;D:\files\repo\com\fasterxml\jackson\dataformat\jackson-dataformat-yaml\2.10.0\jackson-dataformat-yaml-2.10.0.jar;D:\files\repo\com\fasterxml\jackson\core\jackson-core\2.10.0\jackson-core-2.10.0.jar;D:\files\repo\com\fasterxml\jackson\core\jackson-databind\2.10.0\jackson-databind-2.10.0.jar;D:\files\repo\net\bytebuddy\byte-buddy\1.10.1\byte-buddy-1.10.1.jar;D:\files\repo\org\jodd\jodd-bean\5.1.6\jodd-bean-5.1.6.jar;D:\files\repo\org\jodd\jodd-core\5.1.6\jodd-core-5.1.6.jar com.luban.springsourcecodeanalysis.SpringSourceCodeAnalysisApplication
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.0.RELEASE)
2022-02-16 15:02:17.480 INFO 1168 --- [ restartedMain] .l.s.SpringSourceCodeAnalysisApplication : Starting SpringSourceCodeAnalysisApplication on DESKTOP-KGMMDOL with PID 1168 (D:\files\ideaspace\spring-source-code-analysis\target\classes started by ftcs in D:\files\ideaspace\spring-source-code-analysis)
2022-02-16 15:02:17.484 INFO 1168 --- [ restartedMain] .l.s.SpringSourceCodeAnalysisApplication : No active profile set, falling back to default profiles: default
2022-02-16 15:02:17.582 INFO 1168 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-02-16 15:02:17.582 INFO 1168 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-02-16 15:02:19.374 INFO 1168 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-02-16 15:02:19.388 INFO 1168 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-02-16 15:02:19.389 INFO 1168 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.27]
2022-02-16 15:02:19.539 INFO 1168 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-02-16 15:02:19.539 INFO 1168 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1957 ms
Example1静态代码块
Example1构造方法
@PostConstruct执行
2022-02-16 15:02:19.883 INFO 1168 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2022-02-16 15:02:19.908 WARN 1168 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchFieldError: defaultInstance
2022-02-16 15:02:19.908 INFO 1168 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2022-02-16 15:02:19.910 INFO 1168 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-02-16 15:02:19.987 INFO 1168 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-02-16 15:02:20.012 ERROR 1168 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchFieldError: defaultInstance
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1803) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at com.luban.springsourcecodeanalysis.SpringSourceCodeAnalysisApplication.main(SpringSourceCodeAnalysisApplication.java:12) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.2.0.RELEASE.jar:2.2.0.RELEASE]
Caused by: java.lang.NoSuchFieldError: defaultInstance
at org.springframework.web.servlet.mvc.method.annotation.ServletCookieValueMethodArgumentResolver.<init>(ServletCookieValueMethodArgumentResolver.java:40) ~[spring-webmvc-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.getDefaultArgumentResolvers(RequestMappingHandlerAdapter.java:648) ~[spring-webmvc-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.afterPropertiesSet(RequestMappingHandlerAdapter.java:561) ~[spring-webmvc-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1862) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1799) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
... 21 common frames omitted
Process finished with exit code 0
通过百度发现都说的是包重复了,我看了我自己的,没有重复,然后我就顺着这个思路,既然是重复,因为我是springboot项目,也就是说可能我引用的依赖,其实springboot已经自动帮我引用了,只是我不知道,然后我找到那个创建失败的对象requestMappingHandlerAdapter是在webMVCAutoConfiguration中,也就是说是在某个web依赖中,到pom文件中查看,果然两个web相关的包,去掉一个就可以了.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>RELEASE</version>
</dependency>-->