问题
In IBM WebSphere web admin console one can go to Applications -> WebSphere enterprise applications, pick an application and click on "Custom Properties" link. There will be a page to add key-value pairs. How would you access those values from the code? The properties don't seem to end up in System properties nor in ServletContext..
回答1:
I've never seen it used during my 7-year career with IBM WebSphere Application Server. I think that if it's ever used it's so rarely that I'd call the feature a left-over from the past version of IBM WebSphere that supported it.
For application-specific configuration settings I'd strongly recommend web.xml
for web applications or @Resource annotation for web applications and the other application types.
回答2:
This answer will be not exactly on the topic, but it can resolve the issue to define and set configuration properties for Web Applications managed by WebSphere.
The easiest way to define configuration settings for a Web Application under WebSphere is below:
- Define a Web Application settings using the
servlet
initialization parameters:
web.xml
<servlet>
<servlet-name>my-servlet</servlet-name>
<servlet-class>
my.servlet.ClassName
</servlet-class>
<init-param>
<param-name>someConfigurationPropertyName</param-name>
<param-value>This Value Can Be Set</param-value>
</init-param>
</servlet>
- The value of these
servlet
parameters can be changed using Web Administration Console, you will find and can change them inEnterprise Applications > your-web-application-name > Initialize parameters for servlets
回答3:
I tested this on WAS ND 8.5. Adding a custom property to the application adds it to the deployment.xml.
I updated \DefaultApplication.ear with the property name="testprop" value="true". It gets updated here:
C:\WASNEW85\WebSphere\AppServer\profiles\Dmgr01\config\cells\cell01\applications\DefaultApplication.ear.ear\deployments\DefaultApplication.ear
The value shows:
<properties xmi:id="Property_1424805152486" name="testprop" value="true" description="test-forum" required="false"/>
I hope this helps.
回答4:
To set a webcontainer custom property on IBM WebSphere Application Server Version 7 or Version 8
- In the administrative console, click "Servers" and under Servers click "Server Types" and under Server Types click "WebSphere Application Servers"
- Click on the server to which the custom property is to be applied
- Under "Configuration" and "Container settings" click "Web Container Settings" and under Web Container Settings click "Web container"
- Under "Configuration" and "Additional Properties" click "Custom Properties"
- In the Custom Properties page, click "New"
- In the settings page, enter the name of the custom property to be added in the "Name" field and the value to be set for the custom property in the "Value" field. Note that some properties are case sensitive.
- Click "Apply" or "OK"
- Click "Save" in the "Messages" box that appears
- Restart the server for the custom property to take effect
To set a webcontainer custom property on IBM WebSphere Application Server Version 6:
- In the administrative console, click "Servers" and under Servers click "Application Servers"
- Click on the server to which the custom property is to be applied
- Under "Configuration" and "Container settings" click "Web Container Settings" and under Web Container Settings click "Web Container"
- Under "Configuration" and "Additional Properties" click "Custom Properties"
- In the Custom Properties page, click "New"
- In the settings page, enter the name of the custom property to be added in the "Name" field and the value to be set for the custom property in the "Value" field. Note that some properties are case sensitive.
- Click "Apply" or "OK"
- Click "Save" in the "Messages" box that appears
- Restart the server for the custom property to take effect
To set a webcontainer custom property on WebSphere Application Server Version 6 using wsadmin:
- Create a jacl script to add/update the custom property.
- Ensure that the server is running.
- Run the jacl script in wsadmin using "wsadmin -f .jacl
- Restart the server for the custom property to take effect.
来源:https://stackoverflow.com/questions/14229079/defining-custom-properties-in-application-panel-how-to-get-the-value-in-the-co