how to load properties file only once in enterprise application
This is the class which loads properties file which returns static instance;**********************************************************************public class LoadProperties { private static Properties properties = new Properties(); public static Properties getProperties() { return properties; } public static void setProperties( Properties properties) { LoadProperties.properties = properties; }}
This is Listener class mentioned in web.xml which can be read when server starts up;**********************************************************************public class LoadProperties implements ServletContextListener {public void contextInitialized(ServletContextEvent arg0) { //Below properties placed in application server class path in server lib folder with compressed jar; InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("server.properties"); LoadProperties.getProperties().load(inputStream); //value is printed successfully; System.out.println("LoadProperties.."+LoadProperties.getProperties().getProperty("type")); }}
My requirement is How do we read this property(LoadProperties.getProperties().getProperty("type")) in EJB class without loading the properties file once again?because when we load this properties in WAR level we will get once instance of LoadProperties;I dont think same instance will not be propagated in EJB level as well.So Do i need to load same properties once again in EJB classes as well?
my EAR structure is like this;
APP.ear
lib--- jars -- server.properties related jar is placed in the application server class path not in this folder;
ejb.jar
web.war
JavaJava EEJSP
Last Comment
CEHJ
8/22/2022 - Mon
for_yan
As far as I undersatnd, for servelets you coudl use ServletContext Attributes to store your applicaion wide properties, but there are no EJB context Attributes, so there is no way to do it in the same way.
This question is discussed in this rather old trail below. While the tone of the discussion is pessimistic, there are some suggestions there about using entity bean or JNDI to store such application -wise propertis:
This question is discussed in this rather old trail below. While the tone of the discussion is pessimistic, there are some suggestions there about using entity bean or JNDI to store such application -wise propertis:
http://www.velocityreviews.com/forums/t139068-get-and-set-attribute-for-ejb-context-storing-objects.html