搜索
查看
编辑修改
首页
UNITY
NODEJS
PYTHON
AI
GIT
PHP
GO
CEF3
JAVA
HTML
CSS
搜索
盐析白兔
这个屌丝很懒,什么也没留下!
关注作者
热门标签
article
热门文章
1
目标检测YOLO系列算法的进化史
2
油猴插件(Tampermonkey)安装教程_油猴安装教程
3
高并发下生成随机数_c语言 高并发随机数
4
Python之Pandas的常用技能【写入数据】_用pandas向表格中指定的行和列写入数据
5
UNet详解(附图文和代码实现)
6
HTML+CSS简单漫画网页设计成品 蜡笔小新3页 大学生个人HTML网页制作作品_动漫网页设计源代码成品
7
vue项目移动端tabbar--前端_前端 移动端 taber
8
Opencv-Python目标追踪_trackerkcf_create
9
浅谈STM32的三种Boot模式_stm32 boot
10
ScheduledExecutorService 使用
当前位置:
article
> 正文
spring常用的标签@Repository,@controller,@service_spring repository标签
作者:盐析白兔 | 2024-02-15 23:02:03
赞
踩
spring repository标签
在annotaion配置注解中用@Component来表示一个通用注释用于说明一个类是一个spring容器管理的类。即就是该类已经拉入到spring的管理中了。而@Controller, @Service, @Repository是@Component的细化,这三个注解比@Component带有更多的语义,它们分别对应了控制层、服务层、持久层的类。
@Repository标签是用来给持久层的类定义一个名字,让Spring根据这个名字关联到这个类。
例如:
@Repository("userDao")
public class UserDaoImpl implements UserDao{
........................................
}
声明了UserDaoImpl 在Spring容器中叫userDao这个名字。
@Service是用于服务层的IServiceImpl类文件,功能与@Repository类似。
另外标签:@Autowired 用来注入。
例如:
@Autowired
private UserDao userDao;
这样就注入进去了,相当于我们new了个实现类,我们就无需写setter方法了。
我们还得有配置文件进行配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.zxr.manager">
<context:include-filter type="regex" expression=".*DaoImpl"/>
<context:include-filter type="regex" expression=".*ServiceImpl"/>
</context:component-scan>
</beans>
这样就把com.zxr.manager包下的所有.*DaoImpl,.*ServiceImpl都注册关联到Spring容器中去了。
声明:
本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:
https://www.wpsshop.cn/blog/article/detail/87955
推荐阅读
article
Spring Boot +
ElasticSearch
实战之CRUD及多
数据源
配置_
spring
-boot-
starter
-
data
-
elasticsearch
多
数据源
SpringBoot+
ElasticSearch
实现CRUD;ES多
数据源
连接配置;_
spring
-boot-
starter
-
data
-
elasticsearch
多
数据源
spring
-boot-
starter
-
data
-elasticsea...
[详细]
赞
踩
article
Java
/
Kotlin
Spring
Elasticsearch
增删改查教程_
kotlin
elasticsearch
Elasticsearch
基本概念
Elasticsearch
有四种构成存储空间的基本结构:Indices、Types、Documents、Fields。将这四种结构和关系型数据库对比,能更好说明它们是什么:Indices看作Database...
[详细]
赞
踩
article
LWN:
Git
中的
一个
漏洞
!_
git
repository
found
漏洞
关注了就能看到更多这么棒的文章哦~Avulnerabilityin
Git
ByJakeEdgeMarch10,2021DeepLassistedtranslationhtt..._
git
repository
found
漏洞
git
reposito...
[详细]
赞
踩
article
前端开发
环境搭建:新版
Vue
+脚手架
Vue
-Cli
4.3
安装
讲解以及目录结构讲解_
vue
/
cli
-
service
4.3
什么是
Vue
目前前端最主流框架,套用于构建用户界面的渐进式框架。与其它大型框架不同的是,
Vue
被设计为可以自底向上逐层应用。
Vue
的核心库只关注视图层,不仅易于上手,还便于与第三方库或既有项目整合文档地址:https://cn.
vue
js....
[详细]
赞
踩
article
Spring
Boot
与
Logstash
整合_springboot
logstash
ELK可以说是当前对分布式服务器集群日志做汇总、分析、统计和检索操作的很好的一套系统了。而
Spring
Boot
作为一套为微服务而生的框架,自然也免不了处理分布式日志的问题,通过ELK日志系统来处理日志还是很有意义的。在这套系统中,E即为El...
[详细]
赞
踩
article
微服务
框架
(十三)
Spring
Boot
Logstash
日志
采集_
springboot
logstash
本文为
Spring
Boot
中Log4j2对接
Logstash
,进行
日志
采集。Logstah只支持log4j,使用log4j2时需要通过TCP插件调用此系列文章将会描述Java
框架
Spring
Boot
、服务治理
框架
Dubbo、应用容器引擎...
[详细]
赞
踩
article
Spring
整合
Junit
一直报
java
.
lang
.NullPointerException_
junit5
autowire
nullpointerexception
文章目录1.异常信息2.测试代码3.`build.gradle`4.问题分析5.解决方案1.异常信息
java
.
lang
.NullPointerException atcom.wen.basic.app.
Spring
Junit
Test.tes...
[详细]
赞
踩
article
Spring
配置 @
Scope
(
value
= “
prototype
“,
proxyMode
=
Scope
dProxyMode.TARGET_CLASS) 执行过程分析_@
scope
(
value
= "
prototype
")
总结一下create
Scope
dProxy()方法把原始的BeanDefinition的**autowireCandidate属性修改成了false**,因为改了这个值,所以在@Autowired属性注入的时候,就不会考虑到这个原生的Bea...
[详细]
赞
踩
article
Spring
Boot3
整合
Redis
springboot整合redis简单四步即可。Spring
Boot3
整合
Redis
⛰️个人主页: 蒾酒...
[详细]
赞
踩
article
spring
boot
和
spring
cloud
项目中配置文件
application
和
boot
strap
加载
顺序
在前面的文章基础上日志配置如果引用了
spring
cloud
的组件且有
boot
strap和
application
相关文件,启动日志如下如果
boot
strap相关文件存在,先
加载
,然后再
加载
application
相关文件。对应引用了
spring
...
[详细]
赞
踩
article
详解
Spring
Boot
条件装配
Spring
Boot
条件装配是一种强大的特性,它允许我们根据不同的条件来选择性地启用或禁用特定的配置。在实际开发中,我们应该根据具体的需求和场景,合理地使用条件装配,以实现最佳的设计效果。
Spring
Boot
条件装配是一种强大的特性,它允许...
[详细]
赞
踩
article
Spring
Boot
笔记 002 整合
mybatis
做
数据库
读取
MyBatis是一款优秀的持久层框架,它支持自定义SQL、存储过程以及高级映射。MyBatis免除了几乎所有的JDBC代码以及设置参数和获取结果集的工作。MyBatis可以通过简单的XML或注解来配置和映射原始类型、接口和JavaPOJO(...
[详细]
赞
踩
article
Spring
Boot
配置文件
优先级
程序参数Programarguments>VM参数VMoptions>环境变量Environmentvariables>application-dev.yml>application.yml。环境变量Environmentvariables...
[详细]
赞
踩
article
spring
boot
和
spring
cloud项目中
配置
文件
application
和
boot
strap中的值与对应的
配置
类绑定处理
这样参数的顺序正好对应起来最后匹配
boot
strap值的问题,例如项目中使用了nacos中的
配置
中心功能,很多参数不需要在项目中进行
配置
,在nacos中进行指定就可以,但是nacos中的
配置
参数与项目是隔离的。加载完文件转换为Environ...
[详细]
赞
踩
article
spring
boot
打完
jar
包后
使用
命令行
启动
,提示xxx.
jar
中没有主清单属性
有经验的小伙伴会发现,
使用
命令行
启动
虽然能看到项目
启动
后的相关信息,但是关闭
命令行
,项目也就终止了运行,这很不合理,所以我们
使用
。新建文本文件.txt,输入上面命令后,修改后缀名为.bat,然后点击即可
启动
jar
包。后面跟空格,然后是打完的...
[详细]
赞
踩
article
spring
boot
(2.4.x之前版本)和
spring
cloud
项目
中
自动装配的
监听
执行
顺序
综合上述表述,如果引入了BootstrapApplicationListener则优先加载,但是在源码
中
发现如下正好对应了我们平时写的
spring
boot
启动类,可知,在启动时,如果引入了
spring
cloud
组件,会先创建一个子容器来加载...
[详细]
赞
踩
article
springboot
项目
热
部署
实现(
Spring
Boot
DevTools
方式)
Spring
Boot
DevTools
是
Spring
Boot
提供的一个开发工具,旨在提高开发人员在开发阶段的效率。它提供了许多有用的功能,包括
热
部署
、自动重启、自动配置等。
Spring
Boot
DevTools
是一个为开发人员设计的工具,它提供...
[详细]
赞
踩
article
Spring Boot
RestTemplate
请求
证书
问题_
resttemplate
post
请求
证书
忙活了一个月的需求正式上线,第一天就嗷嗷报错,没一条数据是请求成功的。因为程序里插入了监控程序,监控程序报错,毕竟这个项目刚开始引入都是后台处理,不添加监控程序真报错谁也不知道。如果查过10次报错就会发送提示邮件,告诉我们大面积报错了,赶紧...
[详细]
赞
踩
article
Spring
Boot
3.0 GA来啦,
GraalVM
Native Image Support初体验_
graalvm
native
support
Spring
Boot
正式支持云原生,拥抱云原生。_
graalvm
native
support
graalvm
native
support
Spring
Boot
3.0GA来啦,
GraalVM
NativeImageSupport初体验前言2022-11...
[详细]
赞
踩
article
使用
GraalVM
构建
Spring
Boot
3.0 原生
可执行文件
_
graalvm
springboot
GraalVM
NativeImage是
GraalVM
提供的一种能够将
Spring
Boot
程序打包成云原生
可执行文件
的技术,并且比JVM占用更少的内存和更快的启动速度,非常适合使用容器部署和在Faas平台使用。与在JVM运行的应用程序不同,G...
[详细]
赞
踩
相关标签
elasticsearch
java
kotlin
分布式
linux
编程语言
vue
npm
Spring Boot
Logstash
Log4j2
ELK
grok
spring
gradle
junit
spring boot
redis
数据库
spring cloud
后端