- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这可能是非常基本的问题,但有 NPE,所以想确定一下
我是否必须为变量使用相同的资源名称,或者注入(inject)时可以不同?
@Resource(name='foo')
private X foo;
或者可以
@Resource(name='foo')
private X fooxx;
我正在使用第二种情况,其中实例名称与资源名称不同,但得到 NPE
最佳答案
评论是正确的,这应该可以工作......确保类型正确,但问题可能是其他原因。根据Spring docs on @Resource ...
3.9.5 @Resource Spring also supports injection using the JSR-250 @Resource annotation on fields or bean property setter methods. This is a common pattern in Java EE 5 and 6, for example in JSF 1.2 managed beans or JAX-WS 2.0 endpoints. Spring supports this pattern for Spring-managed objects as well.
@Resource takes a name attribute, and by default Spring interprets that value as the bean name to be injected. In other words, it follows by-name semantics, as demonstrated in this example:
public class SimpleMovieLister {
private MovieFinder movieFinder;
@Resource(name="myMovieFinder")
public void setMovieFinder(MovieFinder movieFinder) {
this.movieFinder = movieFinder;
}
}
If no name is specified explicitly, the default name is derived from the field name or setter method. In case of a field, it takes the field name; in case of a setter method, it takes the bean property name. So the following example is going to have the bean with name "movieFinder" injected into its setter method:
关于java - 我可以对 @resouce 使用不同的变量名吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54208433/
我搜索了一段时间,没有找到问题所在 我收到此错误: Unknown provider: $resouceProvider app.js依赖如下: angular.module('r
这可能是非常基本的问题,但有 NPE,所以想确定一下 我是否必须为变量使用相同的资源名称,或者注入(inject)时可以不同? @Resource(name='foo') private X foo;
我的情况是,我想要 angularjs 自动删除方法中定义的参数: 我的定义: var service = $resource(apiConstant.baseUrl + '/website/:act
我正在尝试创建可绘制资源椭圆形 com 矩形形状?我想要下面的形状 但我得到以下信息: 我在用什么: 如何创建我想要的形状?提前谢谢你 最佳答案 试试这个椭圆形的。
嗨,我正在尝试使用 Chef 在新的 CentOS 6.6 上安装 MySQL 来自项目https://github.com/chef-cookbooks/mysql我写了以下脚本 include_r
我正在尝试使用Go客户端为我的Argo工作流容器包含以下代码的资源,当我运行它时,我可以看到Pod正在正确获取,但容器资源字段为空{}。不确定为什么我的代码没有设置资源。对于我在这里做错了什么或错过了
我是一名优秀的程序员,十分优秀!