我遇到了一個問題,我一直在做很多搜索但仍未找到答案。我們在一個URL包含多個數據庫模式,包括模式的測試副本(例如,模式1,模式2,模式1_測試,模式2_測試都在同一個網址)。我試圖通過一個屬性文件來配置每個模式的哪個版本。從屬性文件中獲取模式名稱
我們正在使用Spring和MyBatis的,可惜我是新來的兩個(所以請原諒我的無知或任何錯誤我做描述了這個問題!)
所以在我的Spring配置文件,這是在/ src目錄/主/資源存儲,我有以下摘錄: (我只加「configLocation」屬性,後來加入「sqlSessionFactoryBeanName」屬性)
<!-- define the SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="com.example.domain" />
<property name="configLocation" value="classpath:mybatisConfig.xml" />
</bean>
<!-- scan for mappers and let them be autowired -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.example.something.persistence" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
我mybatisConfig.xml(這是根據存儲/ SRC /米AIN /資源,這應該是在類路徑)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<properties resource="sqlmapconfig.properties" />
</configuration>
sqlmapconfig.properties(在同一文件夾)
schema1=schema1_test
我嘗試引用屬性映射器中的一個文件在com.example.something.persistence:
<select id="test" resultType="result" parameterType="long">
select ${schema1}.table.col
from ${schema1}.table
</select>
當我嘗試用Maven構建失敗一個TE ST:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'schema1' in 'class java.lang.Long'
任何建議,將不勝感激!
」存儲在/ src/main/resources下,它應該在類路徑中「<==你能證實這種情況嗎?你在類路徑中是否有文件夾「/ src/main/resources」,或者你的內部版本是否在某處複製? – 2012-03-23 15:07:41
是的,它在類路徑上。它是一個將被部署到tomcat服務器的web應用程序。 [編輯 - 錯誤提交] 即使我拿出classpath部分並將其保留爲相對url鏈接(它們在同一個文件夾中),它不會改變任何內容。 是否有任何中間步驟可以讀取{$ schema1}來縮小問題的位置? – witnessmenow 2012-03-23 15:19:46
我發現你指定了配置的屬性文件,但在你的映射器文件中使用了屬性引用。據我所知,這些屬性不會傳遞給映射器文件。 你使用了哪個數據庫?你能在你的JDBC URL中指定模式嗎? – 2012-03-23 15:53:39