Field XX required a bean of type 使用@componentscan 解决
来源:互联网 发布:苹果cms收费采集 编辑:程序博客网 时间:2024/06/14 16:59
很少写博客了,似乎就为了让自己不断加深印象来写博客啦~
遇到的问题 是 spring boot 启动不起来 问题 是
Field XXX that could not be found.
给出的建议Action:
Consider defining a bean of type 'XX ‘ in your configuration.
Spring加载外部Bean两种方式
将定义在另外一个带有@Configuration的类中的Bean加载
1. 在Application类中使用@Import指定该类,
2.让@ComponentScan扫描到该类。
大多数使用的2. 实际上是要在spring boot 初始化前加入该类所在的包 进行扫描
在spring boot 主启动main函数上面加上默认的 扫描就好
@ComponentScan(basePackageClasses = {"XX", "XX.XX"})这句会将相应的包进行扫描
如果想用自己的注解时可以使用SpringBootApplication 进行中间转化
自己封装一个启动注解时
public @interface App { @AliasFor(annotation = SpringBootApplication.class, attribute = "scanBasePackages") String[] scanBasePackages() default {}; @AliasFor(annotation = SpringBootApplication.class, attribute = "scanBasePackageClasses") Class<?>[] scanBasePackageClasses() default {};}
当然如果就为了这个两个注解就咩有必要封装啦~ 就是启动是如果加入了其余的还要用这个注解时可以这样封装
要不就直接用
SpringBootApplication
//// Source code recreated from a .class file by IntelliJ IDEA// (powered by Fernflower decompiler)//package org.springframework.boot.autoconfigure;import java.lang.annotation.Documented;import java.lang.annotation.ElementType;import java.lang.annotation.Inherited;import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;import java.lang.annotation.Target;import org.springframework.boot.SpringBootConfiguration;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.boot.context.TypeExcludeFilter;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.FilterType;import org.springframework.context.annotation.ComponentScan.Filter;import org.springframework.core.annotation.AliasFor;@Target({ElementType.TYPE})@Retention(RetentionPolicy.RUNTIME)@Documented@Inherited@SpringBootConfiguration@EnableAutoConfiguration@ComponentScan( excludeFilters = {@Filter( type = FilterType.CUSTOM, classes = {TypeExcludeFilter.class})})public @interface SpringBootApplication { Class<?>[] exclude() default {}; String[] excludeName() default {}; @AliasFor( annotation = ComponentScan.class, attribute = "basePackages" ) String[] scanBasePackages() default {}; @AliasFor( annotation = ComponentScan.class, attribute = "basePackageClasses" ) Class<?>[] scanBasePackageClasses() default {};}
阅读全文
0 0
- Field XX required a bean of type 使用@componentscan 解决
- spring-boot 多数据源配置时出现Field xx in xxx required a bean of type
- mybatis Field xxxMapper in xxxx required a bean of type 'XXXMapper' that could not be found.
- springboot 报错Field XXX required a bean of type XXX that could not be found.
- Field userMapper in com.jm.controller.LoginController required a bean of type 'dao.UserMapper' that
- Field XXX in XXXX required a bean of type XXXX that could not be found.
- Field discoveryClient in com.demo.eureka_client.controller.DcController required a bean of type 'com
- required a bean of type 'org.hibernate.SessionFactory' that could not be found.
- C++报错集合:XX does not name a type;field `XX' has incomplete type
- 编译错误--------:XX does not name a type和field `XX' has incomplete type
- 编译错误 --- does not name a type和field `XX' has incomplete type
- 编译错误 --- does not name a type和field `XX' has incomplete type
- 编译错误 --- does not name a type和field `XX' has incomplete type
- MyBatis映射错误,No qualifying bean of type 'xx.xx.UserDao' available
- Maven多模块开发Action:Consider defining a bean of type '*.*.*' in your configuration解决
- Property or field 'siteUrl' cannot be found on object of type 'xx'
- 两个C++编译错误及解决办法--does not name a type和field `XX' has incomplete type 编译错误一:XX does not name a type 编
- 两个C++编译错误及解决办法--does not name a type和field `XX' has incomplete type
- spring mvc 拦截器 HandlerInterceptor 的使用
- Ajax的使用以及跨域(中)
- 洛谷P3172:[CQOI2015]选数 (DP+数论)
- easyUI 权限管理之角色管理
- 学习之旅(一)
- Field XX required a bean of type 使用@componentscan 解决
- CentOS 6.8下安装和使用CodeBlocks简介
- Python:从UCI数据库下载数据集到内存
- 一个不错的 DPDK & OVS & HyperScan 技术网站; http://syswift.com/
- oracle11g 清理listener.log
- Java 快速排序(QuickSort)原理及实现代码
- SQL子查询
- hadoop知识点总结(二)hdfs分布式文件系统
- JAVA、android常用时间处理方法及类似微信微博发表时间显示