Announcement Announcement Module
Collapse
No announcement yet.
PropertyPlaceholderConfigurer bean not instanced? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • PropertyPlaceholderConfigurer bean not instanced?

    Hi,

    my app seems not instancing propertyplaceholderconfigurer.

    That's my applicationContext-business.xml:

    Code:
    <?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:aop="http://www.springframework.org/schema/aop"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
               http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
               http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
    
    	.......
    
    	<bean id="myappSpecificationRepository" class="myapp.MyAppweSpecificationRepository" >
    		<constructor-arg value="${myapp.directory}" />
    	</bean>
    
    	 <!--                     properties                                   -->
    	 <bean id="propertyConfigurer"
    		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		<property name="location">
    			<value>classpath:myapp.properties</value>
    		</property>
    	 </bean>
    </beans>
    myapp.properties (just a row) -> myapp.directory=mydir

    and this is my web.xml:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <web-app id="springapp" version="2.4"
    	xmlns="http://java.sun.com/xml/ns/j2ee"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    
    
    	<display-name>My App</display-name>
    
    	<description>My App</description>
    
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>
    				classpath*:/applicationContext-business.xml
    		</param-value>
    	 </context-param>
    
    	<!-- To load Spring root WebApplicationContext  -->
    	 <listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    
    	<servlet>
    		<servlet-name>springapp</servlet-name>
    		<servlet-class>
    			org.springframework.web.servlet.DispatcherServlet
    		</servlet-class>
    		<!-- To load WebApplicationContext for Spring FrameworkServlet 'springapp'
    		(with views and controllers stuff) and attach it to root -->
    		<init-param>
    			<param-name>contextConfigLocation</param-name>
    			<param-value>
    			<!-- classpath*:/springapp-servlet.xml -->
    			classpath*:/applicationContext-business.xml
    			</param-value>
    		</init-param>
    		<load-on-startup>2</load-on-startup>
    	</servlet>
    
    	<servlet-mapping>
    		<servlet-name>springapp</servlet-name>
    		<url-pattern>*.htm</url-pattern>
    	</servlet-mapping>
    
    	<!-- it contains a redirect to /login.htm -->
    	<welcome-file-list>
    		<welcome-file>index.jsp</welcome-file>
    	</welcome-file-list>
    
    	<session-config>
    		<session-timeout>30</session-timeout>
    	</session-config>
    
    </web-app>
    I got this error:

    Code:
    Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Error registering bean with name 'myappSpecificationRepository' defined in class path resource [applicationContext-business.xml]: Could not resolve placeholder 'myapp.directory'
    	at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:249)
    	at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75)
    	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:467)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:334)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:91)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:75)
    	at myapp.test.MyAppServiceIntegrationTest.<clinit>(MyAppServiceIntegrationTest.java:28)
    	... 21 more
    what's wrong???

    Thanks,
    Julio

  • #2
    Most likely, typo in you properties file. If you would post i it may help a lot.

    Comment


    • #3
      my properties file is:

      Code:
      myapp.directory=mydir
      my constructor is :

      Code:
      public MyAppweSpecificationRepository(String directory) {....}
      Thanks,
      Julio

      Comment


      • #4
        Try this:

        Code:
        <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
          <property name="location" value="/WEB-INF/config/myapp.properties"/>
        </bean>
        and put your myapp.properties in the /WEB-INF/config/ directory.

        Comment


        • #5
          I already tried it, but it doesn't work.

          I'm using spring 2.0.5

          Thanks,
          Julio

          Comment


          • #6
            Originally posted by julio View Post
            I already tried it, but it doesn't work.

            I'm using spring 2.0.5

            Thanks,
            Julio
            Problem seems not to be with properties file location - if property file is not found (or can not be read for other reasons), then BeanInitializationException("Could not load properties", ex); shall be thrown.

            I'm still almost convinced that you have simple mistyping somewhere.
            When you have posted contents of your property file here have you made copy-paste or simply typed it in again?


            Regards,
            Oleksandr

            Comment


            • #7
              Could be error be in my test? Here:

              Code:
              private static ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
              			new String[] {
              					"/jetty-server-embedded-integration-test.xml",
              					"/applicationContext-business.xml",
              					"/applicationContext-myapp-service-client.xml",
              					"/applicationContext-myapp-service-client-properties.xml",
              					"/applicationContext-myapp-service-client-fs.xml"
              					});
              it's a "two module" application, with 2 application context file (spring remoting) for server and client

              Thanks,
              Julio

              Comment


              • #8
                please ignore this thread

                sometimes work on existent (very buggy) code is not so beauty (bad configuration of web.xml file)

                Thanks,
                Julio

                Comment

                Working...
                X