Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8603041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:13:52+00:00 2026-06-12T02:13:52+00:00

I have created two separate web applications as well as a Restful API Server.

  • 0

I have created two separate web applications as well as a Restful API Server.
They are maven projects checked out as dynamic web projects within eclipse

Some dependancies I am using inlude Spring 3 MVC, Spring Security, Hibernate and JPA.

Both of my web applications and the API make use of a large number of the same domain models, DAO’s and Services in each applications.
They all have their own indepdant copies of model, dao, service.

Structures:

***Consumer App:***

-Model<br/>
..User.java<br/>
..Card.java<br/>
..Purchase.java<br/>
-Dao<br/>
..UserDAO.java<br/>
..CardDAO.java<br/>
..PurchaseDAO.java<br/>
-Services<br/>
..UserService.java<br/>
..CardService.java<br/>
..PurchaseService.java<br/>

***Admin App:***

Same with few different models, dao's and services.

***API Server:***

Same with few different models, dao's and services.

User:

@Entity
public class User implements Serializable
{
    /**
     * 
     */
    private static final long serialVersionUID = -5232533507244034448L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @NotEmpty
    @Size(min=2, max=15)
    private String firstname;

    @NotEmpty
    @Size(min=2, max=15)
    private String surname;

    @NotEmpty
    @Email
    private String email;

    @NotEmpty
    @Size(min=6, max=10)
    private String password;

    @OneToOne(mappedBy="user", cascade={CascadeType.ALL})
    private UserRole userRole;

    @OneToMany(mappedBy = "user", fetch = FetchType.EAGER, cascade = { CascadeType.ALL })
    private Set<Card> cards;

    @OneToMany(mappedBy = "user", fetch = FetchType.EAGER, cascade = { CascadeType.ALL })
    private Set<UserOffer> offers;

    @Temporal(TemporalType.TIMESTAMP)
    private Date dob;

    @NotEmpty
    private String sex;

        .......
}

UserDAO:

@Repository
public class UserDAO extends AbstractJpaDAO<User> implements IUserDAO
{
    @PersistenceContext
    EntityManager entityManager;

    public UserDAO()
    {
        setClazz(User.class);
    }

    public User findOneByEmail(String email)
    {
        return (User) entityManager
                .createQuery("SELECT u FROM User u WHERE u.email = :email")
                .setParameter("email", email).getSingleResult();
    }
}

UserService:

@Service
public class UserService implements IUserService
{
    @Autowired
    private IUserDAO userDAO;

    public UserService()
    {

    }

    @Transactional
    public List<User> getAll()
    {
        return userDAO.findAll();
    }

    @Transactional
    public User getById(Long id)
    {
        return userDAO.findOne(id);
    }

        ...
}

So as you can see, I need to remove these duplications and have one copy of each model, dao and service where possible.

Is the best approach to remove my models, dao’s and services from the web applications and API and place them in seperate projects/modules that should be included as a jar?

Has anyone suggestions on how to approach and implement this?

A brief overview from someone experienced with creating shared modules between multiple spring applications would be great.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:13:53+00:00Added an answer on June 12, 2026 at 2:13 am

    Duplicated code, especially on such a large scale, is always a bad idea. Mark my words. Even if it’s not terrible right now, it will be as soon as you’ll have to modify one of the shared classes. The problems you’ll immediately experience:

    • more work, change needs to be duplicated across all projects/classes
    • it’s easy to make a mistake or forget about something
    • unsynchronized classes will cause you a major headache, both at runtime and during development
    • future developers will have no idea why classes are duplicated and whether subtle changes (due to unsynchronized modifications) were intentional or not.

    Basically you have to create a separate module (common name is good, API is better, something domain-related is best) and depend on it. This separate module has all the common code and is built as a standalone JAR without any dependencies to client, server, etc.

    All the remaining projects should simply depend on the common artifact. maven makes it use to maintain such projects.

    One final hint: common JAR can not only contain classes, but also resources like XML configuration files. If you can, extract common configuration files into this JAR as well and simply include it in each client app. Since all such files will be available on CLASSPATH, Spring doesn’t care where they come from.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have two separate web applications for a site: One for the site itself,
Maybe someone can help me out. I have created a simple web user control,
i have two separate questions; however, since they are very similar i will ask
I have created two imageViews promatically as shown below: public void createImageViews(Integer count){ ImageView[]
I have created two WindowSurface (WPF), and I want to navigate betwen them. I've
I have created two tables & inserted values as shown below . Table 1
I have created two Pages Page1.xaml and Page2.xaml in windows8 metro apps. I have
I have created two DbContexts, one is for application configuration, the second is for
I have created two folders layout and layout-land with two xml files, one for
I have created two forms in my Windows Application. One Form acts as a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.