报错内容:
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in file [C:\Users\愀棤\Desktop\nomal\JAVA_EE\spaceworking.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\fruit_email\WEB-INF\classes\spring-db.xml]: Could not resolve placeholder 'mysql.fruitname' in string value "${mysql.fruitname}"
spring-db.xml代码:
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd">
<context:annotation-config /> <!-- 使用注解方式 -->
<context:component-scan base-package="com.*" />
<!-- alibaba数据源 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="url" value="${mysql.url}" />
<property name="fruitname" value="${mysql.fruitname}" />
<property name="password" value="${mysql.password}" />
<property name="initialSize" value="3" />
<property name="maxActive" value="30" />
<property name="minIdle" value="6" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="true" />
<property name="validationQuery" value="select 1" />
</bean>
<!-- hibernate session工厂1 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" /><!-- 注入dataSource,数据源:如何链接数据库 -->
<property name="packagesToScan" value="com.entity" /> <!-- 指定扫描entity包下的对像 ,使UserEntity1与该hibnate关联 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><!-- 方言是哪种数据库,这里指定数据库为MySql -->
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">false</prop>
<!--validate 加载hibernate时,验证创建数据库表结构 create 每次加载hibernate,重新创建数据库表结构,这就是导致数据库表数据丢失的原因。
create-drop 加载hibernate时创建,退出是删除表结构 update 加载hibernate自动更新数据库结构 以上4个属性对同一配置文件下所用有的映射表都起作用
总结: 1.请慎重使用此参数,没必要就不要随便用。 2.如果发现数据库表丢失,请检查hibernate.hbm2ddl.auto的配置值可以为true,false,update -->
</props>
</property>
</bean>
<!-- 定义事务这个事务管理器是hibernate的 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager"><!-- 指定Hibernet事务管理器 -->
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 配置 Annotation 驱动,扫描@Transactional注解的类定义事务,一般需要在Service,XXXDao层的类前加上@Transactional,不然会提示:No
Session found for current thread -->
<tx:annotation-driven transaction-manager="transactionManager"
proxy-target-class="true" />