-
Oct 25th, 2006, 08:56 PM
#1
NoSuchBeanDefinitionException
I'm using Spring 1.2.7. I have a XML configuration file and corresponding properties file. When I attempt to instantiate a new ClassPathXmlApplicationContext, I get a NoSuchBeanDefinitionException. My XML file looks like
<bean id="placeholderConfig" class="...PropertyPlaceholderConfigurer">
<property name="location" value="app.properties"/>
</bean>
<bean id="anotherBean" class="net.dummy.SomeClass"/>
<bean id="somethingBean">
<property name="someProp" ref="${something.someProp}"/>
</bean>
My app.properties file is simply
something.someProp=anotherBean
The NoSuchBeanDefinitionException CLAIMS that 'anotherBean' is not defined. Which is clearly a FALSE. The wierd thing is that when I place the value 'anotherBean' directly into the property attribute, then I do not get the exception. For example, instead of <property name="someProp" ref="${something.someProp}"/>, I use <property name="someProp" ref="anotherBean"/>, and everything works fine.
Has anyone else run into this problem? I know Spring has problems with circular references, however, I DOUBT this is a circular problem as #1) anotherBean does not depend somethingBean and #2) why a direct substitution instead of trying to pull it out of the properties file 'fix' this problem?
Thanks.
-
Oct 25th, 2006, 11:07 PM
#2
So I think I "lied" a little bit or left out some details. In my properties file, I also defined some configuration for logging (using Apache Commons Logging and Log4J). When I take out the logging properties into its own properties file, then I no longer get the NoSuchBeanDefinitionException. Why is this?
In my main method, I first set the logging properties and then instantiate my ApplicationContext. Here is a snippet of the revised code (see below).
URL url = ClassLoader.getSystemResource("logger.properties") ;
Properties properties = new Properties();
properties.load(url.openStream());
PropertyConfigurator.configure(properties);
String springXml = "spring-config.xml";
ApplicationContext appContext = new ClassPathXmlApplicationContext(springXml);
BeanFactory beanFactory = (BeanFactory)appContext;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules