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 8891055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:38:29+00:00 2026-06-14T22:38:29+00:00

I am learning Spring and I would just like to ask is there a

  • 0

I am learning Spring and I would just like to ask is there a way to assign values to Bean properties during runtime?
All of the examples that I have tried in the internet and books usually implement hard-coded values in xml files.

For example a short tutorial found in this website http://www.dzone.com/tutorials/java/spring/spring-bean-setter-injection-1.html

The User class has getter and setter methods but all of its values are hard-coded at beans.xml. I tried setting values to User’s member variables via the setter method in main() but I got alot of errors.

So am just wondering if this is possible, if it is I would greatly appreciate if you can show short samples or websites that has this tutorial. Thanks in advance.

Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unexpected failure during bean definition parsing
Offending resource: class path resource [SimpleValues.xml]
Bean 'insertValues'; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: <property> element for property 'name' must specify a ref or value
Offending resource: class path resource [SimpleValues.xml]
Bean 'insertValues'
    -> Property 'name'
    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:324)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionElement(BeanDefinitionParserDelegate.java:579)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionElement(BeanDefinitionParserDelegate.java:477)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionElement(BeanDefinitionParserDelegate.java:446)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.processBeanDefinition(DefaultBeanDefinitionDocumentReader.java:311)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:202)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:181)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:140)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:111)
    //More errors 

this is my xml file

<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-2.5.xsd">

    <bean id="insertValues" class="com.SimpleValues.SimpleValues">
        <property name="name"/> 

        <property name="age"/>

        <property name="height"/>

    </bean>

</beans>

main method

public static void main(String[] args) {

        GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
        ctx.load("SimpleValues.xml");
        ctx.refresh();

        SimpleValues inject = (SimpleValues) ctx.getBean("insertValues");
        inject.setName("Andres");
        inject.setAge(20);
        inject.setHeight(7);

        System.out.println("Name: "+ inject.getName()+ " Age: "+inject.getAge()+ " Height: "+inject.getHeight());
    }
  • 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-14T22:38:30+00:00Added an answer on June 14, 2026 at 10:38 pm

    If you read the errors, you’ll see it’s complaining (correctly) that your XML is invalid (you’re using ill-formed <property/> nodes. Assuming you really do have code elsewhere which obtains a reference to insertValues and calls the setters, then simply remove the 3 <property/> nodes from your XML.

    That is, just use:

    <bean id="insertValues" class="com.SimpleValues.SimpleValues" />
    

    That will create your insertValues bean and not call any of the setters.

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

Sidebar

Related Questions

I've only just started learning ruby on rails and I would like to create
I am learning Android via a book and would just like to confirm something.
I just started learning Android yesterday and would like to code a very simple
I'm new to Scala ,just started learning it today.I would like to know how
Learning Spring (3.1.0) and Hibernate (4.1.1). Just wondering what most developers do when handling
I just uncovered this confusion and would like a confirmation that it is what
I've been reading/learning more about Spring lately, and how one would use Spring in
I am learning about Java Bytecodes. I would like to know if I am
Other than learning java, spring, hibernate, servlets, jsp's, how to use eclipse/netbeans, databases like
I am a complete beginner in Python, and would like to start learning it

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.