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

  • Beginner Petclinic question

    I'm learning Spring (you probably figured that out by the title) and I noticed that the vets ArrayList in the SimpleJdbcClinic exists for the life of the session. It seems like it (and SimpleJdbcClinic, see below) should exist only for the request since I don't see any annotations putting it into the session context. Could someone point out what I'm failing to understand?

    Here is the vets class:
    public class Vets {

    private List<Vet> vets;

    public List<Vet> getVetList() {
    if (vets == null) {
    vets = new ArrayList<Vet>();
    return vets;


    The service:
    public class SimpleJdbcClinic implements Clinic, SimpleJdbcClinicMBean {

    private SimpleJdbcTemplate simpleJdbcTemplate;

    private SimpleJdbcInsert insertOwner;
    private SimpleJdbcInsert insertPet;
    private SimpleJdbcInsert insertVisit;

    private final List<Vet> vets = new ArrayList<Vet>();
    @Transactional(readOnly = true)
    public Collection<Vet> getVets() throws DataAccessException {
    synchronized (this.vets) {
    if (this.vets.isEmpty()) {
    return this.vets;

    The controller mapping:

    public ModelMap vetsHandler() {
    Vets vets = new Vets();
    return new ModelMap(vets);

    Once the vets list is created it survives multiple requests.

    Last edited by dpantale; Feb 12th, 2013, 08:01 PM. Reason: Added code to make question clearer

  • #2
    Okay, mystery solved. I didn't realize that default scope for ALL beans is singleton. I had the idea that applied only to @controller beans.