gpt4 book ai didi

java - 在类 'location' 中找不到属性 'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer' 的 setter

转载 作者:行者123 更新时间:2023-12-02 10:28:48 25 4
gpt4 key购买 nike

在设置 PropertyPlaceholderConfigurer 的位置属性时,我在 bean 配置文件中收到此错误。有人可以帮我解决这个问题吗...

错误是

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

这是我的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-core 版本 5.1.2.RELEASEPropertiesLoaderSupport 的源代码,您可以看到该字段现在被命名为 locations 并且存在多个 setter 。

/**
* 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;
}

关于java - 在类 'location' 中找不到属性 'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer' 的 setter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53724385/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com