簡體   English   中英

在類'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer'中找不到屬性'location'的設置器

[英]No setter found for property 'location' in class 'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer'

設置PropertyPlaceholderConfigurer的location屬性時,我的bean配置文件中出現此錯誤。 有人可以幫我解決這個問題嗎?

錯誤是

在類'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer'中找不到屬性'location'的設置器

這是我的employee-servlet.xml文件:

<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:lang="http://www.springframework.org/schema/lang"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/jee 
        http://www.springframework.org/schema/jee/spring-jee-4.3.xsd
        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-4.3.xsd
        http://www.springframework.org/schema/lang 
        http://www.springframework.org/schema/lang/spring-lang-4.3.xsd
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
        http://www.springframework.org/schema/util 
        http://www.springframework.org/schema/util/spring-util-4.3.xsd">

        <context:annotation-config/>
        <context:component-scan base-package="com.controller"/>

    <bean id="jspViewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/view/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages"/>
        <property name="defaultEncoding" value="UTF-8"></property>
    </bean>

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" 
    p:location="/WEB-INF/jdbc.properties"></bean>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
        p:driverClassName="${jdbc.driverClassName}"
        p:url="${jdbc.databaseurl}"
        p:username="${jdbc.username}"
        p:password="${jdbc.password}">
    </bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${jdbc.dialect}</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
    </bean>

    <bean id="employeeDAO" class="com.dao.EmployeeDAOImpl"></bean>
    <bean id="employeeManager" class="com.service.EmployeeManagerImpl"></bean>
    <tx:annotation-driven/>

    <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
</beans>

我實際上已經從以下網站獲取了此示例: https : //howtodoinjava.com/spring-orm/spring-hibernate-integration-example/

您是否在鏈接的示例中查看了使用的spring版本? 他們使用Spring 3.0.5 ,很可能您使用的是最新版本,並且location字段不再存在。

如果查看Spring核心版本5.1.2.RELEASE中PropertiesLoaderSupport的源代碼,您會看到該字段現在被命名為locations並且存在多個設置方法。

/**
 * Set a location of a properties file to be loaded.
 * <p>Can point to a classic properties file or to an XML file
 * that follows JDK 1.5's properties XML format.
 */
public void setLocation(Resource location) {
    this.locations = new Resource[] {location};
}

/**
 * Set locations of properties files to be loaded.
 * <p>Can point to classic properties files or to XML files
 * that follow JDK 1.5's properties XML format.
 * <p>Note: Properties defined in later files will override
 * properties defined earlier files, in case of overlapping keys.
 * Hence, make sure that the most specific files are the last
 * ones in the given list of locations.
 */
public void setLocations(Resource... locations) {
    this.locations = locations;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM