1. 单元测试类与启动类 包路径不一致
java. lang. IllegalStateException: Unable to find a @SpringBootConfiguration , you need to use @ContextConfiguration or @SpringBootTest ( classes= . . . ) with your test
2. 单元测试 @Test类找不到依赖
1.引入对应依赖包
< dependency>
< groupId> org.springframework.boot</ groupId>
< artifactId> spring-boot-starter-test</ artifactId>
< scope> test</ scope>
</ dependency>
2.注意导入 正确的包路径
import org. junit. Test ;
import org. springframework. boot. test. context. SpringBootTest ;
@SpringBootTest
class MallCouponApplicationTests {
@Test
void contextLoads ( ) {
}
}
3. nacos discover未注册进服务中心
1.引入依赖
< dependency>
< groupId> com.alibaba.cloud</ groupId>
< artifactId> spring-cloud-starter-alibaba-nacos-discovery</ artifactId>
</ dependency>
2.配置discovery信息 nacos地址及微服务名称(未配置名字无法注册)
#nacos注册中心 配置信息
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
#微服务名字
application:
name: mall-coupon
3.在启动类上添加注解开启服务
@EnableDiscoveryClient
@MapperScan ( "com.pzhu.member.dao" )
@SpringBootApplication
public class MallMemberApplication {
public static void main ( String [ ] args) {
SpringApplication . run ( MallMemberApplication . class , args) ;
}
}