我想让数据库对象仅在需要时才创建,所以我想做这样的事情
public class Data {
public List<Group> getGroups(){
List<Group> MyList=new ArrayList<Group>();
Connection conn=null;
@ManagedProperty(value = "#{myConnection}")
myConnection getCon;
}
但这不起作用,相反我必须这样做
public class Data {
@ManagedProperty(value = "#{myConnection}")
myConnection getCon;
public List<Group> getGroups(){
List<Group> MyList=new ArrayList<Group>();
Connection conn=null;
}
为什么我不能在函数内创建一个 ManagedProperty ? 我想了一下,在外面应该没问题,因为它会在我创建对象时创建,但无论如何可以将其放在函数内部吗?
最佳答案
您不能使用ManagedProperty函数内部的注释。它只能在 field 上使用。请参阅下面 ManagedProperty 的定义
@Retention(value=RUNTIME)
@Target(value=FIELD)
public @interface ManagedProperty
关于java - 为什么我不能在函数内使用 ManagedProperty ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46279666/