p18谷粒商城各种问题处理!

各种问题处理方式

nullpointerexception异常BrandServlet为空

这是我遇到的最后一个问题,放到第一来讲,一切都以为修改完了最后还是要用Test类上加这两个注解

@RunWith(SpringRunner.class) //junit4
@SpringBootTest(classes = SoybeanProductApplication.class)
//最后如果有其它情况的话 没加注入你真的是小天才
 @Autowired   //<----------一定要加
    BrandService brandService;

导包导的是这两个

import org.junit.Test;
import org.junit.runner.RunWith;

java.lang.IllegalStateException: Failed to load ApplicationContext问题

这个问题是由于SpringBoot 和SpringCloud 版本不兼容的问题 需要换成一致的,具体要去spring官方

SpringCloudSpringBoot
Finchley2.0.x
Finchley.SR1Spring Boot >=2.0.3.RELEASE and <=2.0.9RELEASE
Finchley.SR4Spring Boot >=2.0.3.RELEASE and <=2.0.9RELEASE
Greenwich2.1.x
Hoxton2.2.x2.3.x (Starting with SR5)
2020.0.x aka Ilford2.4.x

我自己成功解决的版本为:

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
 </parent>

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
</dependencyManagement>

packet不对的问题 xxxpacket

这个时候要对应一下测试类和启动类 好好检查报名是否一致 不是要拷贝到一起(是包名一致!!!)这样SpringBoot才能扫描到!!!
在这里插入图片描述

//这是启动类的包
package com.learn.soybean.product;
//测试类的包
package com.learn.soybean.product;

看到没 是一样的噢

其他问题

其他问题多多少少都是比较粗心导致的了

  • 如 : 不小心启动类的注解删了 还有没加特定@MapperScan注解
  • 下面是正确案例
@MapperScan("com.learn.soybean.product.dao") //扫描包 dao中有Mapper就不用了
@SpringBootApplication
public class SoybeanProductApplication {

    public static void main(String[] args) {
        SpringApplication.run(SoybeanProductApplication.class, args);
    }

}
  • 如2 yml文件中 配置写错 或者application
  • 写成什么appilcetion apppissifxx啥乱七八糟的 自己注意一下
spring:
  datasource:
    username: root
    password: root
    url: jdbc:mysql://192.168.56.10:3306/gulimall_pms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
    driver-class-name: com.mysql.cj.jdbc.Driver
    
mybatis-plus:
  mapper-locations: classpath:/mapper/**/*.xml
  global-config:
    db-config:
      id-type: auto
  • 如3 :没service类
    答:那你就赶紧在代码生成器那里给我分页个数打到最大再生成!!!

  • 如4:应该没了吧 最后是测试类一些小失误的代码吧

  • 放源码!

@RunWith(SpringRunner.class) //junit4
@SpringBootTest(classes = SoybeanProductApplication.class)
public class SoybeanProductApplicationTests {

    @Autowired
    BrandService brandService;

    @Test
    public void contextLoads() {
        BrandEntity brandEntity = new BrandEntity();
        brandEntity.setName("小米");
        brandEntity.setDescript("太下头了");
        brandService.save(brandEntity);
        System.out.println("保存成功...");
    }
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值