我應將管理部分與戰爭的其餘部分分開嗎


5

我使用struts2構建了一個Web應用程序。然後,我在同一場戰爭中建立了一個小的管理界面。

隨著時間的流逝,Web應用程序不斷發展,因此管理界面也在不斷發展。現在,我正在考慮在單獨的戰爭中將管理界面與應用程序的其餘部分分開

這是個好主意嗎?由於管理員之爭與Webapp的其餘部分分離,我可以獲得任何性能上的好處。

管理部分主要是關於在數據庫中進行更改/更新/設置,因此它不會直接影響應用程序其餘部分的UI。分開它還可以確保我可以對這兩個部分進行更新而不影響另一個。

[更新]

我無法將管理部件放在本地計算機上。這是一個網絡應用程序。

Do they use the same classes?是的,整個軟件包對於管理員操作而言是不同的,並且視圖也是分開的。

How do you update them?上傳戰爭

Do you use application session?是的,當然,儘管管理員和普通用戶使用了不同的會話。

3

Separating out different parts of a web application from each other as separate wars means that one can stop and restart individual applications at the application server and possibly simplifies the access control on each application. The separate applications means that, in theory one can deploy changes to the admin (take it off line, redeploy it) while the main application is still running (note that theory is emphasized - more on this later).

Thats really about it for benefits. One might see some very slight performance increase on the admin pages because of a reduced number of sessions there. It is unlikely one would see any improved performance on the main application.

Now the implications that make this much more challenging and take away some of the possible gains.

Consider if you have a user object. This has methods on it like changePassword that can be done by the admin or the user.

Consider these two options:

  • you're using hibernate or some other orm to annotate the user table to the user object
  • you've got a data access layer running native queries against the database

You again have two options for these:

  • two copies of the user object / data layer - one in each war
  • one external jar that both wars load

Whenever you make a schema change (anything that necessitates updating the user or the data layer) you will either have at least twice as much work (reload both applications and make sure they stay in sync), or you will have to reload the shared jar and restart both applications (and if the app server is being fussy, restart it).

At the end of the day, you are going to find that you have copied the entire set of data objects (and data layer). The admin may have a few more, but likely everything that is in the main app will be in the admin.

There is a real damager of bugs if the two duplicate the data/model. Furthermore, you'll find yourself duplicating views (the admin view of a user update page vs the main app view of a user update page).

Ultimately, you'll likely find that there are only minor differences in the authorization between the two applications - you want to share the same authentication, the same data, and likely the same views. They are just different controllers for admin and normal user.

From this, its likely best to just keep it all as one application. Don't Repeat Yourself. Don't duplicate the views and don't duplicate the models.