spring注解之——@Service

ops/2024/9/25 8:20:42/


Spring框架中的注解@Service用于将类标记为Spring应用程序上下文中的服务组件。它主要用于指示带注释的类充当应用程序中的服务层组件。

以下是关于注释的一些要点@Service

  1. 业务逻辑:通常,带有注释的类@Service包含业务逻辑。这些类负责封装和实现应用程序的业务规则和流程。

  2. Spring Bean:当 Spring 扫描应用程序中的组件(使用组件扫描或显式配置)时,它会识别带有注释的类,@Service并将它们注册为应用程序上下文中的 Spring bean。

  3. 依赖注入:服务通常使用依赖注入注入到其他 Spring 组件中,例如控制器、其他服务或存储库。这有助于实现应用程序不同层之间的松散耦合。

  4. 事务行为:Spring的事务管理能力常常应用在服务层。默认情况下,Spring 将@Service带注释的类中的方法标记为事务性的,允许您以声明方式控制事务边界。

    java">package org.springframework.stereotype;@java.lang.annotation.Target({java.lang.annotation.ElementType.TYPE})
    @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
    @java.lang.annotation.Documented
    @org.springframework.stereotype.Component
    public @interface Service {@org.springframework.core.annotation.AliasFor(annotation = org.springframework.stereotype.Component.class)java.lang.String value() default "";
    }

  • @java.lang.annotation.TargetService:该注释指定可以应用该注释的程序元素的类型。在这种情况下,指定注释Service只能应用于类型,例如类、接口或枚举。
  • @java.lang.annotation.Retention:该注解指定带有该Service注解的注解应保留多长时间。该值RUNTIME指示注释Service应该在运行时通过反射可用。
  • @java.lang.annotation.Documented:此注释指示用 注释的元素Service应包含在生成的 JavaDoc 文档中。
  • @org.springframework.stereotype.Component:该注解表明它是Spring Framework 提供的注解Service的特化。Component这意味着Service在组件扫描过程中,带有 注解的类将被自动检测并注册为 Spring bean。
  • @org.springframework.core.annotation.AliasFor:该注解表示value()该注解的属性是该注解属性的Service别名。这允许用户在使用或注释类时可以互换使用属性。value()ComponentvalueServiceComponent
  • java.lang.String value() default "";value:这定义了注释中命名的属性Service。它允许用户在使用 注释类时指定自定义值Service。如果未显式提供值,则默认为空字符串。

http://www.ppmy.cn/ops/34436.html

相关文章

string容器

目录 string函数的构造 string赋值操作 string字符串拼接 string字符串查找和替换 string字符串比较 string字符存取 string插入与删除 string字串 string函数的构造 #include<iostream> #include<cstring> using namespace std; void test01() {string s…

《自动机理论、语言和计算导论》阅读笔记:p215-p351

《自动机理论、语言和计算导论》学习第 11 天&#xff0c;p215-p351总结&#xff0c;总计 37 页。 一、技术总结 1.constrained problem 2.Fermat’s lats theorem Fermat’s Last Theorem states that no three positive integers a, b and c satisfy the equation a^n b…

SpringApplicationBuilder启动类

SpringApplicationBuilder 原文链接&#xff1a;http://t.csdnimg.cn/B6L6u

python 学习: 矩阵运算

摘要: 本贴通过例子描述 python 的矩阵运算. 1. 一般乘法 (mm 与 matmul) 代码: input_mat1 torch.tensor([[1, 2, 3, 4],[1, 2, 2, 3]])input_mat2 torch.tensor([[1, 2, 3, 3],[2, 1, 2, 3],[3, 1, 2, 2],[2, 3, 2, 3]])print("input_mat1: ", input_mat1)prin…

C# 用户控件UserControl事件解绑资源释放

用户控件继承子 UserControl 。 现在有个业务需求在UserControl 所在的窗体关闭时解除事件HMouseDown绑定。 因没有相关的Close事件。后来本人想了一个办法在 ROICtlDesigner类的 Dispose 方法中执行相关的释放代码 比如解除事件绑定 释放资源 public partial class ROICt…

CMake使用

一、CMake 是什么 CMake 是一个跨平台的自动化构建系统&#xff0c;它使用配置文件 CMakeLists.txt 来管理软件构建过程。CMake 基于 Makefile 做了二次开发。 二、单个文件目录 # CMake 最低版本号要求 cmake_minimum_required(VERSION 3.16.3)# 工程名 project(CMakeSingle)…

新手必看!场外个股期权的权利金估算公式

场外个股期权的权利金估算公式 场外个股期权的权利金估算公式通常涉及多个因素&#xff0c;这些因素共同决定了权利金的具体数额。虽然具体的估算公式可能因不同的交易平台、交易规则和标的资产而有所差异&#xff0c;但一般来说&#xff0c;权利金的计算会考虑以下几个关键要…

华为 huawei 交换机 配置 MUX VLAN 示例(汇聚层设备)

组网需求 在企业网络中&#xff0c;企业所有员工都可以访问企业的服务器。但对于企业来说&#xff0c;希望企业内部部分员工之间可以互相交流&#xff0c;而部分员工之间是隔离的&#xff0c;不能够互相访问。 如 图 6-4 所示&#xff0c; Switch1 位于网络的汇聚层&#xff0…