当前位置: 首页 > news >正文

网站建设业务的途径的体会link友情买卖

网站建设业务的途径的体会,link友情买卖,郑州做网站公司有多少,微信 小程序Resource介绍 在Spring框架中,Resource 注解是一个JSR-250标准注解,用于自动装配(autowiring)Spring容器中的bean。Resource 注解可以用于字段、方法和方法参数上,以声明依赖注入。 Resource源码 Target({TYPE, FIE…

@Resource介绍

在Spring框架中,@Resource 注解是一个JSR-250标准注解,用于自动装配(autowiring)Spring容器中的bean。@Resource 注解可以用于字段、方法和方法参数上,以声明依赖注入。

@Resource源码

Target({TYPE, FIELD, METHOD})
@Retention(RUNTIME)
@Repeatable(Resources.class)
public @interface Resource {String name() default "";String lookup() default "";Class<?> type() default java.lang.Object.class;enum AuthenticationType {CONTAINER,APPLICATION}AuthenticationType authenticationType() default AuthenticationType.CONTAINER;boolean shareable() default true;String mappedName() default "";String description() default "";
}
源代码截图

@Resource属性介绍

  • name:资源的JNDI名称,装配指定名称的Bean。
  • type:装配指定类型的Bean。
  • lookup:引用指向的资源名称,可以使用JNDI名称指向任何兼容的资源。
  • AuthenticationType:指定身份验证类型。
  • shareable:指定当前Bean是否可以在多个组件之间共享。
  • mappedName:指定资源的映射名称。
  • description:指定资源的描述。

@Resource注解使用场景

  1. 数据库连接池注入:在 Java 应用中,数据库连接池是一个常见的资源。使用 @Resource 注解可以将数据库连接池注入到需要使用数据库连接的类中。

  2. JNDI 资源注入:Java Naming and Directory Interface(JNDI)是一个应用程序设计的API,为开发人员提供了查找和访问各种命名和目录服务的通用、统一的接口,如DNS、LDAP、NIS、CORBA 对象服务等。使用 @Resource 注解可以将 JNDI 资源注入到 JavaBean 中。

  3. 事务管理器注入:在 Java 应用中,事务管理器是一个重要的资源。使用 @Resource 注解可以将事务管理器注入到需要进行事务管理的类中。

  4. 其他资源注入:除了上述资源外,@Resource 注解还可以用于将其他类型的资源注入到 JavaBean 中,如文件资源、网络资源等。

@Resource测试示例代码

示例代码 一

ResourceDemoService类
package com.yang.SpringTest.annotation.resourceLean;/*** <p>ResourceDemoService类</p>** @author By: chengxuyuanshitang* Package com.yang.SpringTest.annotation.resourceLean* Ceate Time 2024-04-12 16:23*/
public interface ResourceDemoService {void demo();
}
ResourceDemoServiceAImpl类
package com.yang.SpringTest.annotation.resourceLean;import org.springframework.stereotype.Service;/*** <p>ResourceDemoServiceAImpl类</p>** @author By: chengxuyuanshitang* Package com.yang.SpringTest.annotation.resourceLean* Ceate Time 2024-04-12 16:26*/
@Service("resourceDemoServiceA")
public class ResourceDemoServiceAImpl implements ResourceDemoService {@Overridepublic void demo () {System.out.println ("===== ResourceDemoServiceAImpl.demo...");}
}
ResourceDemoServiceBImpl类
package com.yang.SpringTest.annotation.resourceLean;import org.springframework.stereotype.Service;/*** <p>ResourceDemoServiceBImpl类</p>** @author By: chengxuyuanshitang* Package com.yang.SpringTest.annotation.resourceLean* Ceate Time 2024-04-12 16:26*/
@Service("resourceDemoServiceB")
public class ResourceDemoServiceBImpl implements ResourceDemoService {@Overridepublic void demo () {System.out.println ("===== ResourceDemoServiceBImpl.demo...");}
}
ResourceDemoController类
package com.yang.SpringTest.annotation.resourceLean;import org.springframework.stereotype.Controller;import javax.annotation.Resource;/*** <p>ResourceDemoController类</p>** @author By: chengxuyuanshitang* Package com.yang.SpringTest.annotation.resourceLean* Ceate Time 2024-04-12 16:27*/
@Controller
public class ResourceDemoController {@Resource(name = "resourceDemoServiceB")private ResourceDemoService resourceDemoService;public void demo () {resourceDemoService.demo ();}}
ResourceDemoConfig配置类
package com.yang.SpringTest.annotation.resourceLean;import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;/*** <p>ResourceDemoConfig配置类</p>** @author By: chengxuyuanshitang* Package com.yang.SpringTest.annotation.resourceLean* Ceate Time 2024-04-12 16:31*/
@Configuration
@ComponentScan(value = {"com.yang.SpringTest.annotation.resourceLean"})
public class ResourceDemoConfig {}
ResourceDemoTest测试类
package com.yang.SpringTest.annotation.resourceLean;import org.springframework.context.annotation.AnnotationConfigApplicationContext;import java.util.Arrays;/*** <p>ResourceDemoTest测试类</p>** @author By: chengxuyuanshitang* Package com.yang.SpringTest.annotation.resourceLean* Ceate Time 2024-04-12 16:32*/
public class ResourceDemoTest {public static void main (String[] args) {AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext (ResourceDemoConfig.class);String[] definitionNames = context.getBeanDefinitionNames ();Arrays.stream (definitionNames).forEach ((definitionName) -> System.out.println (definitionName));System.out.println ("--------------------");ResourceDemoController resourceDemoController = context.getBean (ResourceDemoController.class);resourceDemoController.demo ();context.close ();}}
运行结果




http://www.hkea.cn/news/830436/

相关文章:

  • 怎么建设seo自己网站网站优化推广教程
  • 最新app开发软件石家庄网站建设seo公司
  • 江苏自助建站系统哪家好推广网站要注意什么
  • 唐河做网站关键字搜索引擎
  • 松江专业做网站公司seo视频教程百度云
  • 淄博品质网站建设竞价推广怎么样
  • 搜狗站群系统资源网站优化排名优化
  • 建设一个网站哪家好网站推广优化的原因
  • 做网站的上海公司有哪些情感链接
  • 梧州做网站建设数字营销公司
  • 加强新闻网站建设建议seo高手培训
  • 安丘网站建设制作怎样制作网页设计
  • 食品网站建设优化案例热门职业培训班
  • 龙华新区做网站大地seo视频
  • 网站彩票投注员做啥的真正免费的网站建站平台运营
  • wordpress 中文注册鸡西seo
  • 佛山企业如何建网站seo的内容怎么优化
  • 在什么网站上做自媒体windows优化大师是自带的吗
  • 装修公司的网站怎么做第三方营销平台有哪些
  • 百度公司做网站吗手机网页链接制作
  • 武汉移动网站制作今天新闻最新消息
  • 酒泉建设厅网站百度seo刷排名软件
  • 天津个人网站建设yandex引擎
  • 网站改版建设 有哪些内容网络营销策划方案怎么做
  • 网站建设拾金手指下拉seo的实现方式
  • 北京宣传片湖南seo优化哪家好
  • 下载app 的网站 如何做黑帽seo排名技术
  • 个人是否做众筹网站哪里可以免费推广广告
  • 外贸网站该怎么做青岛百度推广优化怎么做的
  • 网站建设中 网页代码优化关键词排名公司