【springboot项目】连环错

开始是这样的Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader; 


        在pom.xml的依赖中,仔细查看控制台输出你会发现IntelliJ IDEA正在尝试使用JUnit5运行我的测试用例希望使用JUnit4.12运行测试用例,我们查看pom.xml发现junit-jupiter-api这个依赖会导致这个错误

    删除junit-jupiter-api  pom文件中


然后:

java.lang.IllegalStateException: Could not load TestContextBootstrapper [null]. Specify @BootstrapWith's 'value' attribute or make the default bootstrapper class available.

    解决:Pom文件中只留:

        <dependency>

           <groupId>org.springframework.boot</groupId>

           <artifactId>spring-boot-starter-test</artifactId>

           <scope>test</scope>
       </dependency>
        <dependency>
           <groupId>com.github.pagehelper</groupId>
           <artifactId>pagehelper-spring-boot-starter</artifactId>
           <version>1.2.5</version>
       </dependency>
       <dependency>
           <groupId>com.github.pagehelper</groupId>
           <artifactId>pagehelper</artifactId>
           <version>5.1.4</version>
        </dependency>


然后:

java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test


1、@SpringBootTest(classes=Deserializers.Base.class)

类上写换成下面的错:

expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}


1、或者把测试类放到新建的那个和主函数启动类所在包名一致的目录下后

换错,报错如下:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/github/pagehelper/PageInterceptor

    pageHelper的错,所以在配置文件中加入springboot的分页插件和pagehelper的最新版本(当前)

接着报错:

java.lang.IllegalArgumentException: java.net.URISyntaxException: Illegal character in scheme name at index 0: "https://oss-cn-beijing.aliyuncs.com"

    这个问题吧,语法不合法,看看官网也没有问题呀,在啸大神的帮助下,去空格、没有问题了

new OSSClient(endpoint.trim(), accessKeyId.trim(), accessKeySecret.trim());这个空格哪里来的,奇怪了

这些错误之间很少是相互关联的,不过是这次项目启动过程中遇到了,记录一下

再说点其他的


启动命令:

启动java -jar *** &(后台)

不停机启动:nohup java -jar target/spring-boot-scheduler-1.0.0.jar &

启动时读取配置文件: java -jar app.jar --spring.profiles.active=dev

 

Swagger加header https://blog.csdn.net/u014044812/article/details/71473226

 简单来说在swagger配置文件中添加:

  @Bean  
    public Docket api(){  
    //添加head参数start  
        ParameterBuilder tokenPar = new ParameterBuilder();  
        List<Parameter> pars = new ArrayList<Parameter>();  
        tokenPar.name("x-access-token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build();  
        pars.add(tokenPar.build());  
    //添加head参数end  
Docket方法中添加 .globalOperationParameters(pars),如果这样不行你就点进去链接看看吧

小结:

   造成一种很厉害的错觉生气

猜你喜欢

转载自blog.csdn.net/ma15732625261/article/details/80279094
今日推荐