springboot项目踩坑

1.SpringBootApplication启动时会默认扫描主类当前包及子包,如果需要扫描主类当前包外的其他包或不扫描当前包下的特定包或类,可通过下列属性实现:

@SpringBootApplication(scanBasePackages = {"xxx", "xxx"})

2.@EnableFeignClients注解默认也是会扫描注解所在包的当前包及子包,如果需要扫描其他包下的FeignClient,需要单独使用属性指定

@EnableFeignClients(basePackages = ("com.gxfw"))

总结:@SpringBootApplicatoin是用的@ComponentScan扫描,扫描的是Component,包括@Component, @Controller, @Service, @Repository等,而@EnableFeignClients扫描的是@FeignClient,所以在指定扫描路径时要分别指定,否则会报异常:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.gxfw.bbs.feign.ArticleFeignClient' available: expected at least 1 bean which qualifies as autowire candidate. 

3  在SpringBoot中集成MyBatis,可以在mapper接口上添加@Mapper注解,将mapper注入到Spring,但是如果每一给mapper都添加@mapper注解会很麻烦,这时可以使用@MapperScan注解来扫描包。

@MapperScan(basePackages = "com.yuewei.core.mapper")

4 springboot 多模块部署,本地打包的时候提示XXX程序包找不到,解决办法:

<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
</plugin>

猜你喜欢

转载自blog.csdn.net/jswd_50x/article/details/99859809