在启动类上添加
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
SpringBoot @Value用法
yml中声明一些常量
aliyun: oss: file: endpoint: oss-cn-beijing.aliyuncs.com keyid: xxxx keysecret: xxxx bucketname: guli-file-xiaozhao
读取yml配置文件
@Component public class ConstantYmlUtils { //读取配置文件中内容 @Value("${aliyun.oss.file.endpoint.endpoint}") private String endpoint; @Value("${aliyun.oss.file.endpoint.keyid}") private String keyid; @Value("${aliyun.oss.file.endpoint.keysecret}") private String keysecret; @Value("${aliyun.oss.file.endpoint.bucketname}") private String bucketname; }
注意:如果不加${}则直接将“”中内容赋值
SpringBoot整合单元测试
关于SpringBoot单元测试找不到Mapper和Service报java.lang.NullPointerException的错误
根据SpringBoot版本引入依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
设置单元测试
注意添加以下两个注解,EduApplication是主启动类
@RunWith(SpringRunner.class)@SpringBootTest(classes = EduApplication.class) import org.junit.Test; @RunWith(SpringRunner.class) @SpringBootTest(classes = EduApplication.class) public class MyTest { @Autowired private EduCourseMapper courseMapper; @Test public void testdemo01(){ courseMapper.deleteById("1655898309098749953"); System.out.println("springboot单元测试"); } }