SSM(Spring + Spring MVC + MyBatis)專案中,設定檔出現 ${driver} 未被替換的情況,導致資料庫連線失敗。
db.properties 是否正確定義了 driver 屬性。<context:property-placeholder /> 或 PropertySourcesPlaceholderConfigurer 來載入屬性檔。db.properties:
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test
jdbc.username=root
jdbc.password=123456
spring.xml:
<context:property-placeholder location="classpath:db.properties" />
<bean id="dataSource" class="...">
<property name="driverClassName" value="${jdbc.driver}" />
...
</bean>