简体   繁体   中英

How can I replace my web.xml entries with weblogic JNDI?

I need to replace my web.xml entries with something that can be updated without the need of a redeployment. At first, I thought of creating a database table, but then a guy suggested weblogic JNDI. The problem is that I don't know how to do that and don't even know whether this is possible. I've tried to find an answer across the Internet, but couldn't make much progress so far. Can you please help me out with this? Thanks in advance.

Note: This is the very first time I ask a question here, so please be patient.

The answer is to use a deployment plan, which is the standard weblogic way of doing these things. This is quite well described here:

http://middlewaremagic.com/weblogic/?p=5144

However lets assume you need to set something else, an environment variable. If we 1st add the variable to the web.xml:

<env-entry>
    <env-entry-name>directoryPath</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>/data/uploads</env-entry-value>
</env-entry>

This defines a path, that of course maybe different from environment to environment.

We can refer to this by InitialContext, or just by spring JEE:

<jee:jndi-lookup id="directoryPath" jndi-name="directoryPath" resource-ref="true" default-value="/data/uploads"/>

So what is this plan.xml, 1st you need to generate a default one, this you can pinch from the link above, however you can generate your default one by checking this link:

From the docs

Then we need to replace the value we need, as we are using web.xml we need to insert the web.xml bit:

<module-descriptor external="false">
  <root-element>web-app</root-element>
  <uri>WEB-INF/web.xml</uri>
  <variable-assignment>
    <name>directoryPath</name>
    <xpath>/web-app/env-entry/env-entry-value</xpath>
  </variable-assignment>
</module-descriptor>

The variable should defined in the variable section of the plan.xml

<variable>
  <name>directoryPath</name>
  <value>/data/secrets</value>
</variable>
<variable>

Finally update the app (the plan can be uploaded by default by the -plan option) or in the console and specify the plan. In the console, choose deployments, select update and choose the plan from the file system. The app is your current deployment and the plan.xml can be updated as and when. Yes, the application does get restarted, but that can be a planned mild outtage, rather than a full scale redploy. The new directory path will be used. Not the simplest JNDI setting interface I'll grant you, but it does work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM