Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8735981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:11:54+00:00 2026-06-13T10:11:54+00:00

I am messing around and trying out some sample spring code. In this instance

  • 0

I am messing around and trying out some sample spring code. In this instance i am trying to create a string and use it inside another bean. the other bean sets the string in a class and then when i call that class hopefully it should print out the message. however, i get an error message. Please could someone suggest what might be wrong here?

public static void main(String[] args) {
    ApplicationContext applicationContext = new ClassPathXmlApplicationContext("MyConfig.xml");

SetterMessage message = (SetterMessage) applicationContext.getBean("setStringFromBean");
System.out.println(message.getMessage()); 
}

public class SetterMessage {

    private String message = null;
    /**
     * Gets message.
     */
    public String getMessage() {
        return message;
    }

    /**
     * Sets message.
     */
    public void setMessage(String message) {
        this.message = message;
    }
}

<bean id="createString" class="java.lang.String">
<constructor-arg value="Hello from a bean"</constructor-arg>
</bean>

<bean id="setStringFromBean" class="SetterMessage">
    <property name="message" ref="createString" />
</bean>

the error is

Oct 23, 2012 8:36:58 PM
org.springframework.context.support.AbstractApplicationContext
prepareRefresh INFO: Refreshing
org.springframework.context.support.ClassPathXmlApplicationContext@4447393f:
startup date [Tue Oct 23 20:36:58 BST 2012]; root of context hierarchy
Oct 23, 2012 8:36:58 PM
org.springframework.beans.factory.xml.XmlBeanDefinitionReader
loadBeanDefinitions INFO: Loading XML bean definitions from class path
resource [MyConfig.xml] Oct 23, 2012 8:36:58 PM
org.springframework.beans.factory.support.DefaultListableBeanFactory
preInstantiateSingletons INFO: Pre-instantiating singletons in
org.springframework.beans.factory.support.DefaultListableBeanFactory@643ae941:
defining beans [defaultMessage,constructorBean,setterMessage]; root of
factory hierarchy Exception in thread “main”
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
bean named ‘setStringFromBean’ is defined at
org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:549)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at
org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1106)
at Main.main(Main.java:13)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:11:55+00:00Added an answer on June 13, 2026 at 10:11 am

    I had an erroneous comment tag in the xml file and therfore it was not being parsed properly

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been messing around with this for hours trying different ways of ordering by
I'm just messing around with some C++ at the moment trying to make a
Messing around with some CSS trying to learn some stuff as I haven't done
UPDATED: Added some sample code to help clarify. Hi, Feel like this shouldn't be
I am messing around trying to write a small web crawler. I parse out
These days, I've been messing around with the Objective-C runtime, trying to find out
I am just messing around trying to make a game right now, but I
I have been messing around with Leaks trying to find which function is not
I'm not a professional, but I'm messing around with wordpress trying to customize it
I am messing around with ASP.NET MVC 2 Preview 2 and am trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.