@SpringBootApplication(scanBasePackages = {"com.alibaba.nacos.api.*","com.alibaba.nacos.server.*"})
@NacosPropertySource(dataId = "example", autoRefreshed = true)
public class SpringBootStaterApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootStaterApplication.class, args);
}
@Bean
public JPAQueryFactory jpaQueryFactory(EntityManager entityManager) {
return new JPAQueryFactory(entityManager);
}
}
上面要扫描的包的路径不一致,分别在不同的子模块中
根据springboot启动流程,会有自动扫描包没有扫描到相关注解, 默认Spring框架实现会从声明@ComponentScan所在的类的package进行扫描,来自动注入,因此启动类最好放在根路径下面,或者指定扫描包范围spring-boot扫描启动类对应的目录和子目录,这是我从教程里面看到的一句话,试试有没有帮助
@ComponentScan("org.apache") 这样应该可以
@ComponentScan({"org.apache.test","org.apache.test2"}) 或者这样
获取你可以使用通配符表示
@ComponentScan("org.apache.*")