Run multiple applications with the same logic under Struts environment

Introduction

Described how to pass fixed parameters for each Action under Struts environment.

background

Within a single project built with the Struts framework To respond to additional requests from users who want to run multiple applications with the same logic (at a level where switching settings is sufficient by replacing property files, etc.).

If I knew it, I would have made such a configuration from the beginning, It is said that the timing when the test was completed was discovered ...

If your project consists of a single application It's enough to move multiple projects on a project-by-project basis. Originally there are several different applications on board, and I gave up because I want to run multiple applications only for some of them.

You can copy only the relevant logic part and make multiple ones, I don't want the cost of fixing to double every time I fix something.

So, in Struts-config.xml Since parameters can be passed in the parameter attribute of each action tag, We decided to implement it by dividing the link source into multiple parts and changing the parameters passed depending on the link that was stepped on.

Implementation method

Actions are all the same

struts-config.xml


<action path="/linkA" type="com.hogehoge.xxxAction" parameter="AAA">
(Omitted)
</action>

<action path="/linkB" type="com.hogehoge.xxxAction" parameter="BBB">
(Omitted)
</action>

<action path="/linkC" type="com.hogehoge.xxxAction" parameter="CCC">
(Omitted)
</action>

java:com.hogehoge.xxxAction.java


String xxx = ActionMapping.getParameter();
session.setAttribute("_LINK_PARAM_", xxx);

The rest depends on the passed parameters It is OK if you implement only the part that changes the property to be read.

in conclusion

If you know it from the beginning, it is easiest to implement it by preparing an exit for that amount, but If the number of "plurality" is not decided, or if there is a possibility that it will increase or decrease in the future, I feel that this is easier.

Recommended Posts

Run multiple applications with the same logic under Struts environment
FactoryBot Register multiple data with the same model
Setting to start multiple units at the same time with Vagrant
Prepare the format environment with "Rails" (VScode)
Run a DMN with the Camunda DMN Engine