spring boot 中@Autowired注解无法自动注入的错误
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。
</div>
<!--一个博主专栏付费入口-->
<!--一个博主专栏付费入口结束-->
<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-4a3473df85.css">
<div id="content_views" class="markdown_views">
<!-- flowchart 箭头图标 勿删 -->
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path>
</svg>
<h1 id="spring-boot-中autowired注解无法自动注入的错误">spring boot 中@Autowired注解无法自动注入的错误</h1>
在使用springboot main方法启动项目时遇到[@Autowdired]注解无法注入,网上查了很多资料也是一位网上的大神的一句话理通了思路:
异常信息:
异常信息:
Action:Consider defining a bean of type 'com.boot.app.service.bootService' in your configuration.
controller层:
@RestController
@Autowired
private BootService bootService;
@RequestMapping(value="/query",method=RequestMethod.POST)
public String queryByStatus() {
return "query";
}
}
发现注解均正常:
SpringBoot项目的Bean装配默认规则是根据Application类所在的包位置从上往下扫描!“Application类”是指SpringBoot项目入口类。这个类的位置很关键:如果Application类所在的包为:com.boot.app,则只会扫描com.boot.app包及其所有子包,如果service或dao所在包不在com.boot.app及其子包下,则不会被扫描!即, 把Application类放到dao、service所在包的上级,com.boot.Application知道这一点非常关键
Application类:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
<link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-b6c3c6d139.css" rel="stylesheet">
原文地址:https://blog.csdn.net/huihuilovei/article/details/62041734
spring boot 中@Autowired注解无法自动注入的错误的更多相关文章
- Spring Boot中@Scheduled注解的使用方法
Spring Boot中@Scheduled注解的使用方法 一.定时任务注解为@Scheduled,使用方式举例如下 //定义一个按时间执行的定时任务,在每天16:00执行一次. @Scheduled ...
- Spring Boot中的注解
文章来源:http://www.tuicool.com/articles/bQnMra 在Spring Boot中几乎可以完全弃用xml配置文件,本文的主题是分析常用的注解. Spring最开始是为了 ...
- Spring Boot中自定义注解+AOP实现主备库切换
摘要: 本篇文章的场景是做调度中心和监控中心时的需求,后端使用TDDL实现分表分库,需求:实现关键业务的查询监控,当用Mybatis查询数据时需要从主库切换到备库或者直接连到备库上查询,从而减小主库的 ...
- Spring中@Autowired注解与自动装配
1 使用配置文件的方法来完成自动装配我们编写spring 框架的代码时候.一直遵循是这样一个规则:所有在spring中注入的bean 都建议定义成私有的域变量.并且要配套写上 get 和 set方法. ...
- 搭建SSH框架整合Struts2和Spring时,使用@Autowired注解无法自动注入
© 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述: 搭建SSH框架,在进行Struts2和Spring整合时,使用Spring的@Autowired自动注入失败,运行报错java.lan ...
- Spring Boot 中 @SpringBootApplication注解背后的三体结构探秘
概 述 SpringBoot 约定大于配置 的功力让我们如沐春风,在我之前写的文章<从SpringBoot到SpringMVC> 也对比过 SpringBoot 和 SpringMVC 这 ...
- Spring Boot中@ConfigurationProperties注解实现原理源码解析
0. 开源项目推荐 Pepper Metrics是我与同事开发的一个开源工具(https://github.com/zrbcool/pepper-metrics),其通过收集jedis/mybatis ...
- spring boot 中使用swagger 来自动生成接口文档
1.依赖包 <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swa ...
- Spring Boot中yml配置文件Map集合注入及使用方式
yml配置文件 maps: "{key1: 'value1', key2: 'value2'}" java中 @Value("#{${maps}}") priv ...
随机推荐
- 设置多个className
有时候我们需要有选择地设置多个className function myComponent(props) { const myClassName = { 'aaa', {'bbb': props.ne ...
- tf.matmul()报错expected scalar type Float but found Double
tf.matmul(a,b)将矩阵a乘以矩阵b,生成a * b,这里的a,b要有相同的数据类型,否则会因为数据类型不匹配而出错. 如果出错,请看是前后分别是什么类型的,然后把数据类型进行转换.
- hypermesh对msh文件或者cas文件重新命名边界
原视频下载地址: https://pan.baidu.com/s/1c1Thqm 密码: muhe
- rust数据类型
fn main() { //char支持4个字节,支持emoji let jp = "ゆ"; let emoji = "✨"; let ch = "囧 ...
- [C++] 类的成员变量和成员方法
类具有成员变量和成员方法 成员变量用来描述某个对象的具体特征,是静态的,也称为成员属性,这些属性一般设置为私有,仅供类的内部使用. 成员方法用来描述某个对象的具体行为,是动态的,也成为成员函数,这些属 ...
- vue-cli 3.0脚手架搭建项目
1.安装vue-cli 3.0 npm install -g @vue/cli # or yarn global add @vue/cli 安装成功后查看版本:vue -v 2.命令变化 vue cr ...
- 检测是否安装或者开启flash
function flashChecker() { var hasFlash = 0; //是否安装了flash var flashVersion = 0; //flash版本 if(document ...
- postgres开启慢查询日志
1.全局设置修改配置postgres.conf: log_min_duration_statement=5000 然后加载配置: postgres=# select pg_reload_conf() ...
- 解决Ubuntu系统“无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系”的有效方法
ubuntu系统下安装东西,很多时候会出现版本冲突的情况: 有效的解决方法是使用aptitude来帮助降级. 首先安装aptitude 而后使用aptitude来安装前面有冲突的构建,同样也是要使用r ...
- js页面 :函数名 is not defined
最初的写法如下 function GetDateStr(AddDayCount) { var dd = new Date(); dd.setDate(dd.getDate() + AddDayCoun ...