spring boot类加载顺序问题调试 - Go语言中文社区

spring boot类加载顺序问题调试


问题描述:

  在spring boot开发过程中,引入第三方的jar包,第三方第三方包中大概描述:

@Configuration
@ConditionalOnMissingBean(ServiceFactory.class)
@ConditionalOnProperty(prefix = "wwl.openapi", name = {"url", "appId", "appSecret"})
@EnableConfigurationProperties(OpenApiProperties.class)
public class OpenApiAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean(OkHttpClient.class)
    public OkHttpClient openApiOkHttpClient() {
        return new OkHttpClient();
    }

    @Bean
    @ConditionalOnMissingBean(ServiceFactory.class)
    @DependsOn("openApiOkHttpClient")
    public ServiceFactory openApiServiceFactory(DefaultListableBeanFactory beanFactory) {
        OpenApiProperties properties = beanFactory.getBean(OpenApiProperties.class);
        return ServiceFactory.getFactory(beanFactory.getBean(OkHttpClient.class), properties.getUrl(), properties.getAppId(), properties.getAppSecret());
    }

   还有一个propertiy的类;

@ConfigurationProperties(prefix = "wwl.openapi")
public class OpenApiProperties {
    private String url;
    private String appId;
    private String appSecret;

}

在使用过程中,发现一直提是找不到类。后来发现配置中心的参数没有引入导致类包的依赖关系出现问题。

具体调试策略:

application.properties 配置文件中

debug=true

然后再eclipse 项目启动的时候添加

-verbose:class

然后启动后,可以打印出详细的类加载项目,就可以查找处理到底是哪个依赖没有成功导致项目启动失败的

[Loaded org.springframework.web.servlet.mvc.condition.ProducesRequestCondition from file:/D:/tools/apache-maven-3.3.9/myRepository/org/springframework/spring-webmvc/4.3.9.RELEASE/spring-webmvc-4.3.9.RELEASE.jar]
[Loaded org.springframework.web.servlet.mvc.condition.MediaTypeExpression from file:/D:/tools/apache-maven-3.3.9/myRepository/org/springframework/spring-webmvc/4.3.9.RELEASE/spring-webmvc-4.3.9.RELEASE.jar]
[Loaded org.springframework.web.servlet.mvc.condition.AbstractMediaTypeExpression from file:/D:/tools/apache-maven-3.3.9/myRepository/org/springframework/spring-webmvc/4.3.9.RELEASE/spring-webmvc-4.3.9.RELEASE.jar]
[Loaded org.springframework.web.servlet.mvc.condition.ProducesRequestCondition$ProduceMediaTypeExpression from file:/D:/tools/apache-maven-3.3.9/myRepository/org/springframework/spring-webmvc/4.3.9.RELEASE/spring-webmvc-4.3.9.RELEASE.jar]
[Loaded org.springframework.web.servlet.mvc.condition.RequestConditionHolder from file:/D:/tools/apache-maven-3.3.9/myRepository/org/springframework/spring-webmvc/4.3.9.RELEASE/spring-webmvc-4.3.9.RELEASE.jar]
2018-12-20 19:36:44.823  INFO 30948 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hello]}" onto public java.lang.String com.jianlc.controller.HelloController.sayHello()

 

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/x734400146/article/details/85136085
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-03-01 22:08:36
  • 阅读 ( 933 )
  • 分类:

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢