1

I have an enum that I inject into the application scope such as

public void contextInitialized(ServletContextEvent sce) {
       sce.getServletContext().setAttribute("app", ApplicationProperty.INSTANCE);
}

My question, is I have to deploy this web application twice with different property files. Would that cause a problem since I am using an enum, would they share the same values? Thanks.

Application is deployed twice with different context paths and property files (think of as secretKey=12923 and the other one has secretKey=48984 in the property file). First instance deploys it as /ForInternalUse and the other deployment /ForExternalUse. Both deployments are under the same web app server (glassfish).

PS. I have done a small test on glassfish 3.1 but it seems properties are not shared. Second deployment does not impact the first deployment.

user3586195
  • 498
  • 4
  • 15

1 Answers1

1

The two deployments will not share the same enum - they are kept separate unless you specifically share objects between them.

The reason is that an enum is only unique to the classloader that loads it - it is not unique JVM-wide. Web servers provide each context with its own classloader.

See here for how if you wish to share.

Community
  • 1
  • 1
OldCurmudgeon
  • 64,482
  • 16
  • 119
  • 213