How to extend/customize a WAR with another project

后端 未结 5 1573
挽巷
挽巷 2021-02-06 01:03

We have the following scenario with our project:

  • A core web application packaged as a war file (call it Core project).
  • The need to \"customize\" or \"ext
5条回答
  •  天涯浪人
    2021-02-06 01:29

    You might want to look into designing your core app with pluggable features based on interfaces.

    For example say your core app has some concept of a User object and needs to provide support for common user based tasks. Create a UserStore interface;

    public interface UserStore
    {
        public User validateUser(String username, String password) throws InvalidUserException;
        public User getUser(String username);
        public void addUser(User user);
        public void deleteUser(User user);
        public void updateUser(User user);
        public List listUsers();
    }
    

    You can then code your core app (logon logic, registration logic etc) against this interface. You might want to provide a default implementation of this interface in your core app, such as a DatabaseUserStore which would effectively be a DAO.

    You then define the UserStore as a Spring bean and inject it where needed;

    
        
    
    

    This allows you to customise or extend the core app depending on specific customer's needs. If a customer wants to integrate the core app with their Active Directory server you write a LDAPUserStore class that implements your UserStore interface using LDAP. Configure it as a Spring bean and package the custom class as a dependant jar.

    What you are left with is a core app which everyone uses, and a set of customer specific extensions that you can provide and sell seperately; heck, you can even have the customer write their own extensions.

提交回复
热议问题