簡體   English   中英

Spring項目我如何訪問JBoss JNDI數據源

[英]Spring project how do I access JBoss JNDI Datasources

以下是我的Spring Project當前的database.xml文件。 有人可以告訴我什么需要更改,以便可以在其中使用JBoss JNDI數據源。我想這樣做,因此不需要包含數據庫用戶,密碼和URL的配置文件。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx" 
       xmlns:jdbc="http://www.springframework.org/schema/jdbc"

    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                            http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://www.springframework.org/schema/context 
                            http://www.springframework.org/schema/context/spring-context-3.1.xsd
                            http://www.springframework.org/schema/tx
                            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                            http://www.springframework.org/schema/jdbc
                            http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">

                            <!-- 

     Last changed: $LastChangedDate: 2012-11-19 08:53:13 -0500 (Mon, 19 Nov 2012) $
     @author $Author: johnathan.smith@uftwf.org $
     @version $Revision: 829 $

    -->

    <context:property-placeholder location="classpath:app.properties" />

    <context:component-scan base-package="org.uftwf" />

    <tx:annotation-driven transaction-manager="hibernateTransactionManager" />



    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
        destroy-method="close">

        <!-- these are C3P0 properties      --> 
        <property name="acquireIncrement" value="${database.c3p0.acquireIncrement}" />
        <property name="minPoolSize" value="${database.c3p0.minPoolSize}" />
        <property name="maxPoolSize" value="${database.c3p0.maxPoolSize}" />
        <property name="maxIdleTime" value="${database.c3p0.maxIdleTime}" />
        <property name="maxIdleTimeExcessConnections" value="${database.c3p0.maxIdleTimeExcessConnections}" />
        <property name="numHelperThreads" value="${database.c3p0.numHelperThreads}" />
        <property name="unreturnedConnectionTimeout" value="${database.c3p0.unreturnedConnectionTimeout}" />
        <property name="idleConnectionTestPeriod" value="300" />

        <property name="driverClass" value="${database.driver}" />
        <property name="jdbcUrl" value="${database.url}" />
        <property name="user" value="${database.user}" />
        <property name="password" value="${database.password}" />
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="annotatedClasses">
            <list>
                <value>org.uftwf.enrollment.model.Contact</value>
                <value>org.uftwf.enrollment.model.Enrollment</value>
                <value>org.uftwf.enrollment.model.Member</value>
                <value>org.uftwf.enrollment.model.Profile</value>
                <value>org.uftwf.enrollment.model.School</value>

            </list>
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.use_sql_comments">${hibernate.use_sql_comments}</prop>
                <prop key="format_sql">${format_sql}</prop>
            </props>
        </property>
    </bean>

    <bean id="hibernateTransactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
</beans>

我假設您可以在JBoss中配置DataSource 注意,您必須在應用程序服務器配置中定義其JNDI名稱。 一旦有了名稱,只需將dataSource bean替換為:

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/some-name"/>
</bean>

或捷徑:

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/some-name" expected-type="javax.sql.DataSource" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM