如何在glassfish服务器中为mongoDB(no-sql数据库)创建JNDI数据源?

时间:2016-11-15 06:07:14

标签: spring mongodb jpa jndi hibernate-ogm

我知道如何在glassfish服务器中为关系数据库创建JNDI数据源。当我尝试使用数据源连接池为mongoDB创建JNDI数据源时,glassfish中没有可用的选项。 enter image description here

之后我尝试使用JNDI自定义资源URLObject工厂我收到错误

" URLObjectFactory没有必要的网址构建参数" enter image description here

applicationContext.xml文件

这里使用JPA属性对我来说很好。使用JNDI无法正常工作

<?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:tx="http://www.springframework.org/schema/tx"
   xmlns:mvc="http://www.springframework.org/schema/mvc"   
    xmlns:jee="http://www.springframework.org/schema/jee"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
                       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
                       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
                       http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.2.xsd
                       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<context:component-scan base-package="com.mongo"/> 
<context:annotation-config/>
<mvc:annotation-driven />
<tx:annotation-driven transaction-manager="txManager"/>
<jee:jndi-lookup jndi-name="mongo" id="mongoDatasource" />
<bean id="entityManagerFactory"  class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">   
    <property name="persistenceUnitName" value="hbogm" />
    <property name="persistenceProviderClass" value="org.hibernate.ogm.jpa.HibernateOgmPersistence"/>
    <property name="packagesToScan" value="com.mongo.domain"/>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
    </property>
    <property name="dataSource" ref="mongoDatasource" />
    <property name="jpaProperties">
        <props>
            <!--<prop key="hibernate.transaction.manager_lookup_class" >org.hibernate.transaction.SunONETransactionManagerLookup</prop>-->
            <prop key="org.hibernate.ogm.dialect">org.hibernate.ogm.dialect.mongodb.MongoDBDialect</prop>
            <prop key="hibernate.ogm.datastore.provider">org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider</prop>
            <!--<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>-->
            <prop key="hibernate.current_session_context_class">jta</prop>
            <!--<prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.SunOneJtaPlatform</prop>--> 
            <prop key="hibernate.ogm.datastore.database">nvli</prop>
            <prop key="hibernate.ogm.datastore.username">root</prop>
            <prop key="hibernate.ogm.datastore.password">hcdc123</prop>
            <prop key="hibernate.ogm.mongodb.host">127.0.0.1</prop>
            <prop key="hibernate.ogm.mongodb.port">27017</prop>
            <prop key="hibernate.ogm.datastore.create_database">true</prop>
        </props>
    </property>
</bean>
<bean id="txManager"  class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>

0 个答案:

没有答案