12

我正在将 spring 3.0.6-RELEASE 用于基于基本表单的 webapp,并在使用 PropertyPlaceHolderConfigurer 启动时遇到以下错误。不确定是什么导致了这种情况,因为注入属性 pre-mvc3 是通过 bean 完成的,现在使用注释,并且至少从文档/其他帖子中看起来非常简单。

然而,在 tomcat 服务器启动期间的异常抱怨 org.springframework.core.ConstantException: Field 'SYSTEM_PROPERTIES_MODE_ENVIRONMENT' not found in class [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer]

这是我在 spring-servlet.xml 中的内容

<context:property-placeholder location="/WEB-INF/classes/spring.properties"/>

和我的控制器类

@Controller
@RequestMapping("/home")

public class HomeController {

    // @Resource(name="broomManager")
    @Autowired
    private broomManager broomManager;
    private @Value("${spring.broom.maxFileSize}") String inMemoryMaxFileSize;
    private @Value("${spring.broom.fileDestination}") String destFilePath;

..

spring.properties

broom.maxFileSize=100000
broom.fileDestination=/Users/foobar/broom/files/

启动时异常

2012-06-08 02:51:31,900 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] ERROR org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0': Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'systemPropertiesModeName' threw exception; nested exception is org.springframework.core.ConstantException: Field 'SYSTEM_PROPERTIES_MODE_ENVIRONMENT' not found in class [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1361)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:626)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:407)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:467)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:483)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:358)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:325)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1139)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:966)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3956)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4230)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:831)
    at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:720)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:490)
    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1217)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:293)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1306)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1570)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1579)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1559)
    at java.lang.Thread.run(Thread.java:680)
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'systemPropertiesModeName' threw exception; nested exception is org.springframework.core.ConstantException: Field 'SYSTEM_PROPERTIES_MODE_ENVIRONMENT' not found in class [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer]
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358)
    ... 33 more
4

1 回答 1

29

可能会发生以下情况:

  • 您的 Spring 配置文件指向 3.1 模式。
  • 您正在使用 3.0.6 JAR。

他们需要匹配。

于 2012-06-18T22:07:50.380 回答