spring 无法读取properties中的值

来源:互联网 发布:手游存档软件 编辑:程序博客网 时间:2024/06/05 23:43

弄了好久,spring中引入配置文件就是读取不到,也上网找了好多文字,大多都是改引入配置文件的方式如:

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

或者

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

        <property name="locations">
            <list>
                <value>classpath:jdbc.properties</value>
                <!--要是有多个配置文件,只需在这里继续添加即可 -->
            </list>
        </property>

    </bean>

这样引入,都无法达到效果;最后通过修改

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.tgb.mapper;"></property>
<!-- 读取配置文件properties中的值 -->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
<!-- <property name="sqlSessionFactory" ref="sqlSessionFactory"></property> -->
</bean>

<property name="sqlSessionFactory" ref="sqlSessionFactory"></property> 修改为

<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />

就可以读取到了

0 0