Announcement Announcement Module
Collapse
No announcement yet.
Spring Bean question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Bean question

    Hello All,

    I am new to Spring and have a question. I have Java bean/pojo class called course. I am going to be populating the course object with getter/setter methods from a database query. So I will be having multiple instances of the same class for example math, biology etc. Should I declare a spring bean for each course in my xml file or instantiate an object of type course in one my classes? If I do declare the bean definitions in an xml file how do I reference the bean so that I can use the setter method from my DAO class. This is for a web/portlet application. For example if I declare a bean with id="Biology"
    how do I get that specific bean in my class so that the query populates the biology course data into biology? Thanks in advance.
    Last edited by Howler72; Aug 27th, 2008, 12:11 PM.

  • #2
    You should not deploy to spring data objects. In the container mainly services should be present.

    You can define Spring MyDao object fetching data from data base using ie. JdbcTemplate

    ie, you have bean which should be populated the data from data base:
    Person {
    private String name;
    private String surname;
    }

    JdbcTemplate template = new JdbcTemplate( dataSource )
    List persons= jdbcTemplate.query("select * from persons;",
    new RowMapper() {

    public Object mapRow( ResultSet rs, int index )
    throws SQLException {

    Person person = new Person( rs.getString( "name" ),
    rs.getString( "surname" ) );

    return person;
    }
    }

    then you have collection of your Persons

    Comment

    Working...
    X