当前位置:   article > 正文

spring boot类加载顺序问题调试_springboot类加载顺序有问题

springboot类加载顺序有问题

问题描述:

  在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()

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/45603
推荐阅读
相关标签
  

闽ICP备14008679号