Spring - 从 JNDI 设置属性值

标签 spring properties jndi

这是我之前问题的后续部分 Spring and Hibernate - changing dialect

例如,如果我有这段 .xml

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="SpringMVCTest" />
    <property name="jpaProperties">
        <props>
            <prop key="hibernate.dialect" >

            </prop>
        </props>
    </property>
</bean>

现在,我想设置hibernate.dialect到 jndi 通过 jdbc/dialect 公开的值,但是当我输入 <jee:jndi-lookup jndi-name="jdbc/MyDataSource"/>我得到Invalid content was found starting with element 'jee:jndi-lookup'. No child element is expected at this所以我怀疑我不能在 prop 中添加任何标签。

那么,有什么方法可以将 jndi 资源插入到此属性中吗?

最佳答案

不完全确定,但您应该可以在这里使用 Spring-EL,如下所示:

<jee:jndi-lookup id="dialect" jndi-name="..." />


<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="SpringMVCTest" />
    <property name="jpaProperties">
        <props>
            <prop key="hibernate.dialect" >#{dialect}</prop>
        </props>
    </property>
</bean>

关于Spring - 从 JNDI 设置属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12179607/

相关文章:

c# - C# 属性总是有备份字段 "behind the scene"吗?

java - 查找 JNDI 用于错误报告的设置

java - Spring 无法加载 JDBC 驱动程序类错误

spring - Tomcat 未加载 Dispatcher Servlet (ClassNotFoundException)

c# - 在包装 PInvoke 东西的属性的 get 函数中放置大量代码是不好的做法吗?

tomcat - Pentaho Kettle 使用普通的老式 tomcat JNDI

java - 尝试将消息推送到 Activemq 时出现 NamingException

Spring Boot Java 映射实体到 DTO : array literal (strings) INSTEAD of array of objects

spring - Spring 的 @RequestBody byte[](长度大于预期)有什么问题?

Swift:access.property 和 access.method()