Resource Configuration

The resources include:5 IA64 servers,1 CE(x86——64), 1Postgresq(x86_64)

 

NFS server is 192.168.21.243 (/opt/app),it installed MPI and mounted to other 4 worker nodes. In addition, it mounted some dir to all WN, 188 and 229.

NFS server is 159.226.3.188 (/disk2/osg/app), it installed condor and mounted to 229. However, 188 uses condor in a different dir (/opt/osg/condor)

`@Resource` 是 Java 中用于依赖注入的注解,属于 **Java EE 的标准注解(JSR-250)**,在 Spring 框架中也被广泛使用。它主要用于自动注入 Bean,可以用于字段、构造器、方法(如 setter 方法)等位置。 --- ### 一、`@Resource` 的基本使用 `@Resource` 默认按 **名称(name)** 进行自动装配,如果找不到对应名称的 Bean,则会按 **类型(type)** 注入。 --- ### 二、示例代码 #### 1. 定义一个 Service 接口及其实现类 ```java public interface UserService { String getUserInfo(); } ``` ```java import org.springframework.stereotype.Service; @Service("userService") // Bean 名称为 "userService" public class UserServiceImpl implements UserService { @Override public String getUserInfo() { return "User Info"; } } ``` #### 2. 使用 `@Resource` 注入 Bean ```java import javax.annotation.Resource; import org.springframework.stereotype.Component; @Component public class UserController { // 默认按名称匹配,对应 @Service("userService") @Resource private UserService userService; public void showUserInfo() { System.out.println(userService.getUserInfo()); } } ``` --- ### 三、指定名称注入 你可以显式指定要注入的 Bean 名称: ```java @Resource(name = "userService") private UserService userService; ``` --- ### 四、与 `@Autowired` 的区别(Spring 中常见) | 特性 | `@Resource` | `@Autowired` | |------|-------------|--------------| | 来源 | Java EE (JSR-250) | Spring 特有 | | 默认注入方式 | **按名称**(name) | **按类型**(type) | | 是否支持 `required` 属性 | 不支持 | 支持,默认 `required = true` | | 使用范围 | 字段、方法(如 setter) | 字段、构造器、方法、参数等 | --- ### 五、完整 Spring 示例 ```java import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @Configuration @ComponentScan(basePackages = "com.example") public class AppConfig { } ``` ```java import org.springframework.stereotype.Component; @Component public class AppRunner { @Resource private UserController userController; public void run() { userController.showUserInfo(); } } ``` ```java import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; public class MainApp { public static void main(String[] args) { ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class); AppRunner appRunner = context.getBean(AppRunner.class); appRunner.run(); } } ``` --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值