Extending Spring Lemon

Spring Lemon comes with a few base classes, which you need to extend and configure. In this section, we are going to do that.

AbstractUser

Spring Lemon comes with an AbstractUser entity, which you need to extend as below:

@Entity
@Table(name="usr")
public class User extends AbstractUser<User,Long> {

    private static final long serialVersionUID = 2716710947175132319L;   
}

The Long generic parameter above is the type of the primary key.

In the next section, we are going see how to add new a field to this class. For more details, refer the book Spring Framework REST API Development - A Complete Blueprint.

LemonController

The handlers for Spring Lemon API are coded in the abstract LemonController class. Extend it as below:

@RestController
@RequestMapping("/api/core")
public class MyController extends LemonController<User, Long> {

}

LemonService

Spring Lemon comes with an abstract LemonService class, which has the service methods used by LemonController. Extend it as below:

@Service
public class MyService extends LemonService<User, Long> {

    @Override
    public User newUser() {
        return new User();
    }

    @Override
    public Long parseId(String id) {
        return Long.valueOf(id);
    }
}

LemonService has modular methods that you can override. At the least, you need to override the newUser and parseId methods, as above. We are going to see a couple of more examples in the next section. For more details, refer the documentation and resources.

AbstractUserRepository

Finally, you need to extend Spring Lemon's AbstractUserRepository, as below:

public interface UserRepository extends AbstractUserRepository<User, Long> {

}

results matching ""

    No results matching ""