Monday, December 10, 2012

Spring Social with JavaConfig (Part 7)


In the previous section, we have discussed the View layer along with Thymeleaf. In this section, we will focus on the Domain, Repository, Service, and Controller classes.

Table of Contents

Click on a link to jump to that section:
  1. Functional Specs
  2. Generate OAuth keys
    • Facebook
    • Twitter
  3. Spring Social configuration
  4. Spring Security configuration
  5. JavaConfig
  6. View with Thymeleaf
  7. Layers
    • Domain
    • Repository
    • Service
    • Controller
  8. Running the application
    • Clone from GitHub
    • Create the Database
    • Run with Maven and Tomcat 7
    • Run with Maven and Jetty 8
    • Import to Eclipse
    • Validate with W3C



Our domain layer consists of two simple classes: and By annotating these classes with @Entity we're declaring these classes as JPA entities and consequently will be persisted to a database.

The User class contains the following properties: first name, last name, username, role, and password. For the Role class, we only have two values: an admin and a regular user.

Although this is not part of the domain layer, we've included the UserDto here. This DTO is used for transferring user information to the view layer.


We have five controllers:
  • AccessController is responsible for managing login and signup requests
  • FacebookController is responsible for handling Facebook requests
  • TwitterController is responsible for handling Twitter requests
  • UserController is responsible for handling User CRUD operations
  • MediatorController simply handles call to the root page


We have a simple repository. There's nothing much to explain here.


We have two services:
  • UserService is used for handling user-related CRUD operations
  • RepositoryBasedUserDetailsService is used for retrieving user details for authentication purposes


In the next section, we will study how to build and run our application. We will use Maven, Tomcat, and Jetty to run the app. We'll also study how to import the project in Eclipse. Click here to proceed.
StumpleUpon DiggIt! Blinklist Yahoo Furl Technorati Simpy Spurl Reddit Google I'm reading: Spring Social with JavaConfig (Part 7) ~ Twitter FaceBook

Subscribe by reader Subscribe by email Share


  1. This is a great tutorial! I've learnt a lot from it.

    Mark, can you explain why you used the @JsonManagedReference annotation in your JPA entities?

    Also, maybe you would like to continue your tutorial by explaining what happens on the client-side of your application (e.g. how does the client browser create, process, and send JSON? I see some of the UserController methods producing JSON). This would be awesome!

    And finally: What about having a demo running somewhere online so that users can play with it?


  2. Can you explain what if someone wants to sign up to your page using facebook?

  3. Good Post. truly It takes such a lot time to push and find traffic from social media, the matter is it ne'er consistent. we must always take into account Organic searches whereas victimization social name and obtaining links from smart social networks like Google and will not simply provide some traffic however conjointly smart links to diary.

  4. generate OAuth keys for Facebook and Twitter (Online Java Training) Generate OAuth keys Java Training in Chennai Consumer key and Consumer secret values: J2EE Training in Chennai

  5. Your blogging is really more than wonderful and we hope for more creativity because you really are capable of that creative
    العاب سباق سيارات 2018
    العاب سباق

  6. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

    core java training in Electronic City

    Hibernate Training in electronic city

    spring training in electronic city

    java j2ee training in electronic city