SpringBoot之依赖注入DI
@Component
@Service
@Controller
@Repository
@Inject:JSr-330提供的注解
@Autowire:Spring提供的注解
@Resource:JSR-250提供的注解
三者可以注解在set方法上,也可以注解在属性上,习惯性注解在属性上
使用@Service注解声明当前类似spring管理的一个Bean。
package com.wisely.heighlight_spring4.ch1.di; import org.springframework.stereotype.Service; @Service public class FunctionService { public String sayHello(String world) { return "Hello" + world; } }
1、声明当前类似spring管理的一个Bean。欢迎大家加我qq:1038774626探讨技术问题。
2、@Autowire将FunctionService实体类注入UseFunctionService中
package com.wisely.heighlight_spring4.ch1.di; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class UseFunctionService { @Autowired private FunctionService functionService; public String sayHello(String world) { return functionService.sayHello(world); } }
1、@Configuration注解当前类是一个配置类
2、@ComponentScan注解扫描当前包下所有包含@Component、@Service、@Controller、@Repository的类,并注册为Bean。
package com.wisely.heighlight_spring4.ch1.di; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; /** * * @Configuration 当前类是配置类 * @ComponentScan 自动扫描报名下所有使用 @component @service @controller @repository 的类, * 并注册为Bean * */ @Configuration @ComponentScan("com.wisely.heighlight_spring4.ch1.di") public class DiConfig { }
相关推荐
vue-springboot基于BS构架的失物招领系统设计与实现java毕业论文.docx
公司质量管理体系的构架---按过程分类讲义.doc
公司质量管理体系的构架---按过程分类(讲义).docx
软件工程-分布式系统构架-讲义
OAA构架-ACFP技术介绍-D.docx
OAA构架-ACSEI技术介绍-D.docx
软件工程-分布式系统构架-讲义
OAA构架-ACSEI技术介绍.pdf
OAA构架-ACFP技术介绍.pdf
IRF智能弹性构架-IRF2.0技术白皮书-D.docx
IRF智能弹性构架-IRF2.0技术介绍-D.docx
构架-产品组成数据库管理系统-提升企业管理水平.doc
IRF智能弹性构架-IRF2.0技术白皮书.pdf
IRF智能弹性构架-IRF2.0技术介绍.pdf
移动通信网络构架-ppt.ppt该文档详细且完整,值得借鉴下载使用,欢迎下载使用,有问题可以第一时间联系作者~
Active Directory管理和构架-第3部分(AD数据库的维护与操作主机角色)
SpringBoot非官方教程 | 第七篇:springboot开启声明式事务 SpringBoot非官方教程 | 第八篇:springboot整合mongodb SpringBoot非官方教程 | 第九篇: springboot整合Redis 构架文档篇 SpringBoot非官方教程 | 第...
项目系统构架师----完全攻略,想要成为构架师并不是难事,在于好的资料,欢迎各位下载和学习。
此项目基于springboot-dubbo-mybatis构架一个通用的开发 分布式框架 项目介绍 基于springboot+dubbo+Mybatis提供整套公共微服务服务模块:服务模块,控制层模块。 组织结构 springboot-dubbo-mybatis └──...
Nger是一套以依赖注入、装饰器为核心的 多端开发, 前后台统一构架 解决方案