I’m new to Spring and have run into a problem with some of my bean definitions. I have the following classes:
I was hoping to use the User object on my JSP’s so that I can access some common attributes in the following manner:Code:public class User { private UserType userType = null; public User (UserType userType) { this.userType = userType; } public UserType getUserType() { return userType; } public void setUserType(UserType type) { userType = type; } } public abstract class UserType { //some abstract methods; } public abstract class Customer extends UserType { //some abstract methods; } public class Staff extends UserType { public Staff() {} } public class Business extends Customer { public Business() {} } public class Individual extends Customer { public Individual () {} }but I’m running into problems because UserType is abstract.Code:<spring:bind path="user.userType.someCommonAttribute">
I read the Spring reference guide section on Abstract and Child Bean Definitions, but I’m not sure how to define the User and UserType beans since UserType is an abstract class and also an attribute of User. I was looking into bean factories, but I’m not sure if that is the right approach. I would think this would be a fairly common issue, but didn’t have any luck finding answers when I searched the forums. Does anyone have any advice? Thanks in advance.


Reply With Quote