spring 的数据源配置出错Error creating bean with name 'dataSource' defined

如果spring配置是使用这种方式传递的properties文件
这里是直接以容器来加载文件
但是username这个属性已经存在在容器中和配置文件中的属性冲突了

所以在配置数据源的时候
传递给username的value使用${username}得不到正确的值

<context:property-placeholder location="classpath:properties/dbconfig.properties" />
"dataSource" class="..." init-method="init" destroy-method="close">
        "username" value="${username}" >

解决:

1.在db.properties将username属性修改一下

uname: root

然后在spring配置的dataSource里修改属性值:

<property name="username" value="${uname}" >

2.修改spring配置的

<context:property-placeholder location="classpath:properties/dbconfig.properties" />

替换,
以这种方式引入配置文件
是以配置第三方bean的方式配置属性,所以这个bean中的属性是不会和容器中的属性冲突的

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     
      <property name="location" value="classpath:properties/dbconfig.properties" />
    bean>

这里记录下…

你可能感兴趣的:(spring 的数据源配置出错Error creating bean with name 'dataSource' defined)