Injecting the UserService

To display a user, you need to use the respective service. To use a service, you need to inject it using Spring.

Context

To find out the name of a service, please refer to Naming Conventions for Services. For user management, there is an instance of de.hybris.platform.user.UserService with the ID userService.

Procedure

  1. Add an instance variable and a setter method to the UserController to hold this service.
    import de.hybris.platform.servicelayer.user.UserService;
    
    ...
    
    private UserService userService;
    
    @Required
    public void setUserService(final UserService userService)
    {
    	this.userService = userService;
    }
  2. Modify the Spring bean definition of the controller.
    <bean name="/user.html" class="org.training.web.controllers.UserController">
    	<property name="userService" ref="userService"/>
    </bean>
  3. The result is that a bean named userService is injected into the property of the same name.