Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'hibernate.dialect' in string value "${hibernate.dialect}"
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'sessionFactory' defined in class path resource [applicationContext.xml]
附上我的配置文件
<?xml version="1.0" encoding="UTF-8"?>
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<context:property-placeholder location="classpath:db.properties"/>
<!-- 整合hibernate的核心配置文件:hibernate.cfg.xml -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!-- 干掉:工具类
还是要读取hibernate的核心配置文件
-->
<!-- <property name="configLocation" value="classpath:hibernate.cfg.xml"></property> -->
<!-- 干掉:hibernate.cfg.xml
数据源、属性、映射文件
-->
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<array>
<value>com/lhj/pojo/user.hbm.xml</value>
</array>
</property>
</bean>
<!-- 数据源 -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${hibernate.driver}"></property>
<property name="url" value="${hibernate.url}"></property>
<property name="username" value="${hibernate.username}"></property>
<property name="password" value="${hibernate.password}"></property>
</bean>
<!-- 事物管理bean -->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 事物管理 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- propagation:事物的传播特性
REQUIRED:有就使用,没有的话,就创建事物
REQUIRES_NEW:每次都创建一个新的事物
-->
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 配置切面 -->
<aop:config>
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.bjsxt.service.*.*(..))"/>
</aop:config>
<!-- 管理dao -->
<bean id="userDaoImpl" class="com.lhj.dao.impl.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 管理service -->
<bean id="userServiceImpl" class="com.lhj.service.impl.UserServiceImpl">
<property name="userDaoImpl" ref="userDaoImpl"></property>
</bean>