[英]Why can't I use ManagedProperty inside a function ?
I want to make the DB object be created only when it's required, so I want to do something like this 我想只在需要时才创建数据库对象,所以我想做这样的事情
public class Data {
public List<Group> getGroups(){
List<Group> MyList=new ArrayList<Group>();
Connection conn=null;
@ManagedProperty(value = "#{myConnection}")
myConnection getCon;
}
But that doesn't work, Instead I have to do it like this 但这是行不通的,相反,我必须这样做
public class Data {
@ManagedProperty(value = "#{myConnection}")
myConnection getCon;
public List<Group> getGroups(){
List<Group> MyList=new ArrayList<Group>();
Connection conn=null;
}
Why can't I make a managedProperty inside the function ? 为什么我不能在函数内部创建ManagedProperty? I thought about it and it should be okay to be outside since it'll be created when I create the object but is there anyway to make it inside the function ?
我考虑了一下,应该可以放在外面,因为它是在创建对象时创建的,但是无论如何都可以在函数内部创建它?
You can't use ManagedProperty annotation inside the function . 您不能在函数内部使用ManagedProperty批注。 It can be only used on a field.
它只能在字段上使用。 See the definition of the ManagedProperty below
请参阅下面的ManagedProperty的定义
@Retention(value=RUNTIME)
@Target(value=FIELD)
public @interface ManagedProperty
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.