2014-12-04 87 views
0

我正在为Glassfish创建一个新的资源适配器。 它使用具有在管理控制台中设置的属性的连接池。 连接器连接池 - >其他属性 - > name = url,value = 127.0.0.1 我想从资源适配器读取此属性。 (例如,从我的托管连接实现类)如何从资源适配器读取连接池设置?

我试着检查文档和在线示例,但未找出如何执行此操作。

回答

0

这是几乎所有带有连接池的j2ee容器上的Web应用程序的常见方式。

InitialContext ctx = new InitialContext(); 
    //The JDBC Data source that we just created 
    DataSource ds = (DataSource) ctx.lookup("url here"); 
    Connection connection = ds.getConnection(); 
+0

感谢您的回复。我没有提到它,但我使用会话bean,而不是一个Web应用程序。问题是如何访问配置属性而不是资源适配器。 – Severin 2014-12-09 09:26:34

0
@Connector(reauthenticationSupport = false, transactionSupport = TransactionSupport.TransactionSupportLevel.NoTransaction) 
public class SocketResourceAdapter implements ResourceAdapter { 

/** The logger */ 
private static Logger log = Logger.getLogger("SocketResourceAdapter"); 

/** Name property */ 
@ConfigProperty(defaultValue = "DefaultMessage", supportsDynamicUpdates = true) 
private String name; 

@ConfigProperty(defaultValue = "---", type = String.class) 
private String url; 

@ConfigProperty(type = Integer.class) 
private Integer port; 


public String getUrl() { 
    return url; 
} 
public void setUrl(String url) { 
    this.url = url; 
} 

public Integer getPort() { 
    return port; 
} 
public void setPort(Integer port) { 
    this.port = port; 
} 

,然后我可以只是在资源适配器使用的getURL()。 起初它不起作用,因为我设置了连接工厂的属性而不是资源适配器。

相关问题