Sep 15 2012

Learning Spring

Category: English posts,TechnicalIuliana @ 23:47

A few months ago the company where I am currently employed sent me to Belgrad to train me in Spring Core. The training lasted 4 days and at the end I was supposed to take the Spring Core certification exam and pass it.

I delayed that for a while, but because now I have some spare time I decided it was time for me to do this thing. So I went over the slides and the spring code samples again. But after doing some mock tests I concluded I will most likely fail the certification, because the official materials were not enough so I started reading Spring in Action. Still I noticed that in the tests there was still stuff that I hadn’t covered. So I started reading Spring Reference. And because I have some problems in retaining information just by reading it, I stared to test the recommended examples. And this is where I hit some walls.

But before telling you what is not clear for me I shall tell you what technologies I’m using for development: Maven 3.0.0, Jdk 1.7, Intellij Idea 11.1.3 and Spring 3.1.2 (I know the certification is for 3.0, but as the Spring reference manual has 840 pages, I might as well read about the new and useful stuff added in 3.1)

The first problem I had was with the compound property names. I tried using them. Idea does not recognize them and my test fails.

These are my beans:

public class SimpleBean {
    private int numericValue;
    private String stringValue;

    public int getNumericValue() {
        return numericValue;

    public void setNumericValue(int numericValue) {
        this.numericValue = numericValue;

    public String getStringValue() {
       return stringValue;

    public void setStringValue(String stringValue) {
       this.stringValue = stringValue;

    public String toString() {
       return numericValue + "," + stringValue;

public class CompoundBean {

   private SimpleBean simpleBean;

   public void setSimpleBean(SimpleBean simpleBean) {
       this.simpleBean = simpleBean;

   public String toString() {
     return "CompoundBean instance: " + simpleBean.toString();

And this is my configuration:

<bean id="simpleBean" class="class="simpleBean""/>
<bean id="compoundBean" class="CompoundBean">
    <!-- <property name="simpleBean" ref="simpleBean"/>-->
    <property name="simpleBean.numericValue" value="10" />
    <property name="simpleBean.stringValue" value="aaaaaa" />

In the documentation is said that the property bean has to be initialized, in my case the simpleBean property. So I tried initializing simpleBean in the Compound bean constructor. It did not work: NotReadablePropertyException: Invalid property ‘simpleBean’.
I tried adding this <property name=”simpleBean” ref=”simpleBean”/>  in the configuration file and I got the same exception.

So… what am I missing?

[Later edit]: And  the answer is… I was missing a getter. :D Thank you costelush!

Tags: ,

4 Responses to “Learning Spring”

  1. costelush says:

    I have little to none experience with Spring, but … shouldn’t the “bean” node have a property named “class” to specify the bean’s class ? The way you pasted the configuration, I think you assume that the “id” also gives you the bean’s class, which I don’t think if it’s correct.

    Btw, I think the correct config is:

    If you still get errors, you may try to add the getter for simpleBean prop in CompoundBean.

  2. Iuliana says:

    It had a class, I just erased them when editing the code to put in on the blog, for some reason. :D (I fixed that)

    The getter did it, I feel so silly right now.

  3. george says:

    Eu am fost la un curs de spring la bucuresti tinut de Wmware, a fost foarte fain, trainer-ul era norvegian sau suedez oricum tare tipul.
    Daca tot folosesti Spring 3 de ce nu folosesti adnotari ? @Component, @Entity .. te scapa de multe batai de cap mai ales ca nu trebuie sa completezi asa multe fisiere de configurare.

  4. Iuliana says:

    Folosesc adnotări, dar la examen vor fi întrebări din toată materia. Așa că testez și configurări XML și cam tot ce nu prea am folosit până acum.

Leave a Reply