Note that there are some explanatory texts on larger screens.

plurals
  1. POService bean without getters and setters
    primarykey
    data
    text
    <p>I am using spring mvc and I have a service class called UserManager. The class is used to manage a collection of users like add user and delete user from colection. Basicaaly it provides all the information about a collection of users. This class is used by controllers to access user collection information. Now the problem is I have to use it as a bean for spring injection. But a bean should have getters and setters only. So i am confused as to how i implement this class.</p> <p>here is the code for UserManager</p> <pre><code>import com.bo.user.UserBO; /* * UserManager class is a service class which provides service to Controller for managing the users in the system. * It has a collection _allUserMap which maintains the users inside the system all through the life of system. * It manages the addition, deletion and updation of users. * UserBO is the service which helps UserManager access the users, individually, from Database */ @Service public class UserManager{ @Autowired private UserBO userBo; private static Map&lt;Integer,User&gt; _allUserMap = new HashMap&lt;Integer, User&gt;(); /* * Method populates the _allUserMap * using userBo */ @PostConstruct public void loadAllUsers(){ Integer id = null; List&lt;User&gt; _allUserList = userBo.listAllUser(); System.out.println("&lt;--------Initializing all user map---------&gt;"); for(User user : _allUserList){ id = user.getId(); _allUserMap.put(id, user); } } /* * Adds the user after checking if the user exists * @param User:Takes the User to add from the Controller * @Return boolean User added or not * Beta 1.1 validation for correct user addition form input */ public boolean addUser(User user){ boolean userAdded = false; if (hasUser(user)){ userAdded = false; }else{ userBo.save(user); userAdded = true; } return userAdded; } /* * Checks if the user is already present * @Param User * @Return is user present */ private boolean hasUser(User formUser){ boolean isUser = false; User user = null; for(Entry&lt;Integer, User&gt; entry: _allUserMap.entrySet()){ user = entry.getValue(); if(user.equals(formUser)){ isUser = true; } return isUser; } return isUser; } /* * @Param User * @Return String : message gives what feild is alreay in database */ public String matchCredentails(User formUser){ String message = ""; User user = null; for(Entry&lt;Integer, User&gt; entry: _allUserMap.entrySet()){ user = entry.getValue(); if(user.getEmail().equals(formUser.getEmail())){ message = "Email alreay exists+"; } if(user.getMobileNumber()== formUser.getMobileNumber()){ message = message + "Mobile number alreay exists+"; } if(user.getUserName().equals(formUser.getUserName())){ message = message + "UserName alreay exists+"; } } return message; } } </code></pre> <p>here is how i am accessing it in controller</p> <pre><code> @Controller public class UserController { //These are the instances of the service providing bean and not the state of the spring controller @Autowired private UserManager userManager; </code></pre> <p>My question is simple... should i make this class a bean. because this class is not a simple pojo by definition.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload