问题描述
- spring-mybatis数据库配置文件读取不了
-
<?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:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd"> <context:property-placeholder location="classpath:config.properties" /> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" > <!-- <property name="driverClassName" value="com.mysql.jdbc.Driver" /> --> <!-- <property name="url" value="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8" /> --> <!-- <property name="username" value="root" /> --> <!-- <property name="password" value="root" /> --> <property name="driverClassName" value="${driverClassName}" /> <property name="url" value="${url}" /> <property name="username" value="${username}" /> <property name="password" value="${password}" /> </bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="mapperLocations" value="org/mydemo/mapper/*.xml"></property> </bean> <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate"> <constructor-arg ref="sqlSessionFactory" /> </bean> </beans>
把注释解掉他就能正常,
好多人说是因为sqlSessionFactory在context:property-placeholder之前已经加载了
所以driverClassName是空,请问代码该怎么改呢?
解决方案
Mybatis+ Spring 配置文件
mybatis与spring整合(基于配置文件)
mybatis与spring整合(基于配置文件)
解决方案二:
求大神解答!!!!!!!!!!!!!!!!!!!!!!!!!!
解决方案三:
大家一起学习,一起努力
解决方案四:
${driverClassName} 可以取到值吗?
解决方案五:
@{driverClassName} 用这个试试
时间: 2025-01-19 13:08:54