Jakarta ee 在spring框架中设置bean属性

Jakarta ee 在spring框架中设置bean属性,jakarta-ee,servlets,spring-mvc,properties,javabeans,Jakarta Ee,Servlets,Spring Mvc,Properties,Javabeans,我正在努力完成本教程: 不幸的是,我被困在第四章。我明白了 org.springframework.beans.factory.BeanCreationException. 我的代码与本教程中的代码相同,只是有一点不同:我有另一个版本的spring库。我随附的罐子列表: commons-logging-1.1.1.jar jstl-1.2.jar org.springframework.aop-3.1.2.RELEASE.jar org.springframework.asm-3.1.2.R

我正在努力完成本教程:

不幸的是,我被困在第四章。我明白了

org.springframework.beans.factory.BeanCreationException.
我的代码与本教程中的代码相同,只是有一点不同:我有另一个版本的spring库。我随附的罐子列表:

commons-logging-1.1.1.jar
jstl-1.2.jar
org.springframework.aop-3.1.2.RELEASE.jar
org.springframework.asm-3.1.2.RELEASE.jar
org.springframework.aspects-3.1.2.RELEASE.jar
org.springframework.beans-3.1.2.RELEASE.jar
org.springframework.context.support-3.1.2.RELEASE.jar
org.springframework.context-3.1.2.RELEASE.jar
org.springframework.core-3.1.2.RELEASE.jar
org.springframework.expression-3.1.2.RELEASE.jar
org.springframework.instrument.tomcat-3.1.2.RELEASE.jar
org.springframework.instrument-3.1.2.RELEASE.jar
org.springframework.jdbc-3.1.2.RELEASE.jar
org.springframework.jms-3.1.2.RELEASE.jar
org.springframework.orm-3.1.2.RELEASE.jar
org.springframework.oxm-3.1.2.RELEASE.jar
org.springframework.spring-library-3.1.2.RELEASE.libd
org.springframework.test-3.1.2.RELEASE.jar
org.springframework.transaction-3.1.2.RELEASE.jar
org.springframework.web.servlet-3.1.2.RELEASE.jar
org.springframework.web.struts-3.1.2.RELEASE.jar
org.springframework.web-3.1.2.RELEASE.jar
例外情况:

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productManager' defined in ServletContext resource [/WEB-INF/springapp-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
    PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'products' threw exception; nested exception is java.lang.UnsupportedOperationException
我被卡住时的位置:

springapp-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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">

    <!-- the application context definition for the springapp DispatcherServlet -->

    <bean id="productManager" class="springapp.service.SimpleProductManager">
        <property name="products">
            <list>
                <ref bean="product1"/>
                <ref bean="product2"/>
                <ref bean="product3"/>
            </list>
        </property>
    </bean>

    <bean id="product1" class="springapp.domain.Product">
        <property name="description" value="Lamp"/>
        <property name="price" value="5.75"/>
    </bean>

    <bean id="product2" class="springapp.domain.Product">
        <property name="description" value="Table"/>
        <property name="price" value="75.25"/>
    </bean>

    <bean id="product3" class="springapp.domain.Product">
        <property name="description" value="Chair"/>
        <property name="price" value="22.79"/>
    </bean>

    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename" value="messages"/>
    </bean>

    <bean name="/hello.htm" class="springapp.web.InventoryController">
        <property name="productManager" ref="productManager"/>
    </bean>

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

</beans>


我能做些什么来解决这个问题?要使用Spring Framework 3.1实现此功能,我必须做些什么?

看看SimpleProductManager代码:

package springapp.service;

import java.util.List;

import springapp.domain.Product;

public class SimpleProductManager implements ProductManager {

    public List<Product> getProducts() {
        throw new UnsupportedOperationException();
    }

    public void increasePrice(int percentage) {
        throw new UnsupportedOperationException();        
    }

    public void setProducts(List<Product> products) {
        throw new UnsupportedOperationException();        
    }

}
包springapp.service;
导入java.util.List;
导入springapp.domain.Product;
公共类SimpleProductManager实现ProductManager{
公共列表产品(){
抛出新的UnsupportedOperationException();
}
公共无效增量价格(整数百分比){
抛出新的UnsupportedOperationException();
}
公共产品(列出产品){
抛出新的UnsupportedOperationException();
}
}

当Spring调用setter时,它抛出UnsupportedOperationException。因此,事情按预期的方式运行。

看看SimpleProductManager代码:

package springapp.service;

import java.util.List;

import springapp.domain.Product;

public class SimpleProductManager implements ProductManager {

    public List<Product> getProducts() {
        throw new UnsupportedOperationException();
    }

    public void increasePrice(int percentage) {
        throw new UnsupportedOperationException();        
    }

    public void setProducts(List<Product> products) {
        throw new UnsupportedOperationException();        
    }

}
包springapp.service;
导入java.util.List;
导入springapp.domain.Product;
公共类SimpleProductManager实现ProductManager{
公共列表产品(){
抛出新的UnsupportedOperationException();
}
公共无效增量价格(整数百分比){
抛出新的UnsupportedOperationException();
}
公共产品(列出产品){
抛出新的UnsupportedOperationException();
}
}

当Spring调用setter时,它抛出UnsupportedOperationException。因此,事情按预期的方式运行。

您能提供此
BeanCreationException
的完整堆栈跟踪吗?您能提供此
BeanCreationException
的完整堆栈跟踪吗?