【发布时间】:2010-12-29 21:14:30
【问题描述】:
我已将 webapp (war) 部署到 Glassfish v3,并试图让它从自定义资源中定义的属性中读取。
在我的应用中,我将属性定义为:
@Resource(mappedName = "TestServletProperties")
private Properties properties;
并像这样使用它:
protected void doGet(final HttpServletRequest request,
final HttpServletResponse response) throws ServletException,
java.io.IOException
{
String propertyOne = properties.getProperty("testServlet.propertyOne");
String propertyTwo = properties.getProperty("propertyTwo");
StringBuffer buffer = new StringBuffer("Properties Retrieved\n");
buffer.append("Property One: " + propertyOne + "\n");
buffer.append("Property Two: " + propertyTwo + "\n");
try
{
response.getWriter().write(buffer.toString());
}
catch (Exception ex)
{
try
{
log.warn("Exception thrown", ex);
response.getWriter().write(ex.getStackTrace().toString());
}
catch (IOException io)
{
log.warn("IOException thrown", io);
}
}
}
在 Glassfish 中,我创建了一个名为 TestServletProperties 的 JNDI 自定义资源,类型为 java.util.Properties,并使用工厂类 org.glassfish.resources.custom.factory.PropertiesFactory。在资源中有一个属性“fileName”,其值设置为属性文件的绝对路径:
/Program Files/glassfishv3/glassfish/domains/domain1/applications/Test/WEB-INF/classes/TestServlet_lab.properties
我也试过
c:\Program Files\glassfishv3\glassfish\domains\domain1\applications\Test\WEB-INF\classes\TestServlet_lab.properties
我已确认该文件存在并包含引用的属性。不幸的是,我在回复中的两个值都返回“null”。
有什么想法吗?
【问题讨论】:
-
我为这个问题创建了一个错误:java.net/jira/browse/GLASSFISH-15402
标签: properties jndi glassfish-3