×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

HELP!!! HELP!!! J2EE application configuration problems.

I am working on a J2EE project. We need to store some configuration information for our J2EE applications. We use EJB, JMS, and Databases.

The question is WHERE to put and How to get application or server configuration information? We store the application configuration information into an XML file. We put this XML file into jboss\bin\input and use a plain java class to read configuration parameter. All other EJB will access the plain Java class to get configuration parameters.

However, access to the filesystem from EJBs is not allowed in J2EE specification despite that our method is indirect access XML file by EJB. I know that I can put configuration in a database *sounds* like a good idea - but I think there will be a performance hit - and the relational model is not necessarily good for properties with a hierarchy.

I would like to get some informed opinions - some feedback on how other people have tackled this problem.

Thanks!!!!
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / HELP!!! HELP!!! J2EE application configuration problems.
    I am working on a J2EE project. We need to store some configuration information for our J2EE applications. We use EJB, JMS, and Databases.

    The question is WHERE to put and How to get application or server configuration information? We store the application configuration information into an XML file. We put this XML file into jboss\bin\input and use a plain java class to read configuration parameter. All other EJB will access the plain Java class to get configuration parameters.

    However, access to the filesystem from EJBs is not allowed in J2EE specification despite that our method is indirect access XML file by EJB. I know that I can put configuration in a database *sounds* like a good idea - but I think there will be a performance hit - and the relational model is not necessarily good for properties with a hierarchy.

    I would like to get some informed opinions - some feedback on how other people have tackled this problem.

    Thanks!!!!
    • 没用过jboss,不明白你卡在哪了。通常的做法是servlet load configuration, pass it to slsb, then persistence layer(entity bean, jdbc, hibernate or whatever),应该是不会有任何问题的。
      • I just don't know where to put the XML file and how EJB (say sessionBean) can access the XML file for J2EE application configuration.
    • xxxxx.class.getResourceAsStream("file path")
      • But file access is not alowed in EJB. Enven though, in my application, XML file is accessed by a singleton class and EJB call this class. I am not sure this is good or not.
        • No, you can read file from ejb, package it in JAR. I've did it before for read public key file. in your case, maybe put it as env-entry in deployment descriptor file.
    • or storing environment entry elements (env-entry) into the deployment descriptor.
    • Suggestion, using a help class to load the conf xml from startup listener, pass it on to EJB container
      you are right, EJB should never access resource directly, (could be fired if my team member doing that, ), a help class to load the config in web startup listener, later on pass this config to application context that EJB container could access. Using a lookup class to find the config and keep in cache for performance. This is not a specific Jbosss related implementation, but JBoss has it own class loader, which is too container specific, not suggest to use that.
      • 我觉得这是正解.只是不明白1.EJB container 如何访问application context? 2.如何lookup config,3 如何keep in cache
        • there are three options that i could think of right now.......
          1. using IOC light container like Springframe work, put into bean application context, then spring will inject the configuration you want to EJB context, EJB could access the config at any time. or
          2. keep it in web tier applicaion context, when the client create EJB, pass the config in, (create(Parameter param), check with spec), web tier application context is a cache.

          3. bind in JNDI tree after container started (not suggested, since JNDI tree is container specific and not guaranteed to work the way you want )
          • Don't make sample things complex. I don't think it's best way.
            • 你对, 俺经常OVER ENGINEERING
    • This typical problem has been discussed for long long time...
      "The bean's "runtime environment properties" (i.e Context.lookup( "java:comp/env/..." )) are what this is for - providing runtime configuration to your bean."

      "Refer to section 24.1.2, "Programming Restrictions", of the specification (EJB 2.0). Beans are strictly prohibited from accessing either the local filesystem via classes of the java.io package or the system ClassLoader, both being typical means for accessing properties files. Possible ways around these restrictions are through other resource manager classes such as a URL connection or the JNDI Filesystem Service Provider. Both of these methods, however, may prove to be more troublesome than they are worth."

      "Use either the bean's "runtime environment" or a database to provide configuration data to your bean."