简体   繁体   English

获取在Application Server中配置的数据源实例?

[英]Getting Datasource instance which is configured in Application Server?

I have configured a Datasource in JBOSS EAP 6.3.2 using Admin console. 我已经使用管理控制台在JBOSS EAP 6.3.2中配置了数据源。

I want to know what are the ways in which we can get the instance of this Datasource? 我想知道以什么方式可以获取此数据源的实例? Can we use @Resouce , @Inject annotations to get the Datasource? 我们可以使用@Resouce@Inject批注来获取数据源吗?

Or should we use the old JNDI lookup? 还是应该使用旧的JNDI查找?

Can anyone please help me understand this? 谁能帮我理解这一点?

I have never used Jboss EAP but as it's a Java EE 6 Server, you should be able to inject your datasource through @Resource annotation. 我从未使用过Jboss EAP,但由于它是Java EE 6服务器,因此您应该能够通过@Resource注释注入数据源。

If it works the same as JBOSS AS 7, you should : 如果它与JBOSS AS 7相同,则应:

  • Define your datasource in standalone.xml standalone.xml定义数据源
  • Inject the datasource specifying the lookup attribute of @Resource 注入指定@Resourcelookup属性的数据源
@Resource(lookup = "java:jboss/MyDataSource")
private DataSource m_dataSource;

I am using weblogic and I am using the lookup for getting connection. 我正在使用weblogic,并且正在使用查找来获得连接。 This may help you. 这可能对您有帮助。

public Connection getConnection(){
    DataSource dataSource = null;
    Connection connection = null;
        try {
                InitialContext initContext;
                initContext = new InitialContext();
                dataSource = (DataSource) initContext.lookup("jdbc/MyDatasource");
            try {
                connection = dataSource.getConnection();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }catch (Exception e) {
            e.printStackTrace();
        } 
    return connection;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Boot:收到此错误-无法配置数据源:未指定'url'属性,并且无法配置任何嵌入式数据源 - spring boot: getting this error - Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured “配置数据源失败:未指定‘url’属性,无法配置嵌入式数据源。” springboot应用程序中的错误 - 'Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.' error in springboot application 无法配置数据源:未指定“url”属性,无法配置嵌入式数据源//无法找到 application.properties - Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured //Cant find application.properties 配置服务器无法配置数据源:未指定“url”属性并且无法配置嵌入式数据源 - Config-Server Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured Tomcat JDBC 在服务器上配置并包含在应用程序 WAR 中 - Tomcat JDBC configured on Server and included in Application WAR 在javafx中获取应用程序实例 - Getting application instance in javafx Application Server JDBC资源的DataSource或ConnectionPoolDataSource - DataSource or ConnectionPoolDataSource for Application Server JDBC resources 无法配置数据源:未指定“url”属性,并且无法配置嵌入式数据源。 运行应用程序时出现dis错误 - Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Getting dis error while running app 无法配置数据源:无法配置嵌入式数据源 - Failed to configure a DataSource: no embedded datasource could be configured Websphere 自由中的数据源 Mbean - 获取实例未找到异常 - DataSource Mbean in websphere liberty - getting instance not found exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM