使用适用于Eclipse的Oracle Enterprise Pack,我创建了一个Enterprise Project并将其命名为:
属性DemoEAR
还创建了一个PropertiesDemoEARWeb模块,在其中放置了这段代码
(在PropertiesDemoEARWeb / Java资源/ src / com.project.util内部):
package com.project.util; public class PropertiesFileHandler extends ApplicationLifecycleListener { private static final String FILE = "C:/etc/error.properties"; public void preStart(ApplicationLifecycleEvent evt) { System.out.println("\n\n\t\tInside preStart() method\n\n"); InputStream is = evt.getApplicationContext().getAppClassLoader().getResourceAsStream(FILE); try { Properties convertedProps = convertStreamToProperties(is); String userMissingError = convertedProps.getProperty("USER_MISSING_ERROR"); System.out.println("\n\n\t\tuserMissingError = " + userMissingError + "\n\n"); } catch (Throwable e) { e.printStackTrace(); } } public Properties convertStreamToProperties(InputStream is) throws IOException { System.out.println("\n\n\t\tInside convertStreamToProperties() method\n\n"); Properties props = new Properties(); if (is == null) { throw new FileNotFoundException("property file '" + FILE + "' not found"); } else { props.load(is); return props; } } }
内部属性DemoEAR / EarContent / META-INF / weblogic-application.xml
我声明性地添加了以下侦听器:
<?xml version="1.0" encoding="UTF-8"?> <wls:weblogic-application xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-application" > <!--weblogic-version:10.3.5--> <wls:application-param> <wls:param-name>webapp.encoding.default</wls:param-name> <wls:param-value>UTF-8</wls:param-value> </wls:application-param> <wls:listener> <wls:listener-class> com.project.util.PropertiesFileHandler </wls:listener-class> </wls:listener> </wls:weblogic-application>
右键单击PropertiesDemoEAR / Export / EAR文件/目标:
C:\ Oracle \中间件\ user_projects \ domains \ MyDomain \ autodeploy
通过Eclipse运行WebLogic 11g时,在控制台中收到以下错误消息:
[ERROR] AdapterManager - ServletContainerAdapter manager not initialized correctly. <oracle.tip.adapter.apps.AppsConnectionFactory> ConnectionManager cm: weblogic.connector.outbound.ConnectionManagerImpl@12433e7-eis/Apps/Apps ManagedConnectionFactory mcf: oracle.tip.adapter.apps.AppsManagedConnectionFactory@4303022b <Jun 30, 2011 5:50:24 PM PDT> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID '1309481424487' for task '0'. Error is: 'weblogic.management.DeploymentException: ' weblogic.management.DeploymentException: at weblogic.application.internal.flow. BaseLifecycleFlow$CreateListenerAction.run(BaseLifecycleFlow.java:176) at weblogic.security.acl.internal. AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120) at weblogic.application.internal.flow. BaseLifecycleFlow$BaseAction.invoke(BaseLifecycleFlow.java:104) at weblogic.application.internal. flow.HeadLifecycleFlow.createListener(HeadLifecycleFlow.java:117) Truncated. see log file for complete stacktrace Caused By: java.lang.ClassNotFoundException: com.project.util.PropertiesFileHandler at weblogic.utils.classloaders. GenericClassLoader.findLocalClass(GenericClassLoader.java:297)
问题:
(1)我可能做错了什么?为什么找不到我的PropertiesFileHandler类?
(2)我的属性文件的位置(c:/etc/error.properties)是否合适,还是应该在MyDomain目录中?
(3)是否有默认目录或简单的配置区域,WebLogic会加载属性文件,这些文件可由WebLogic中运行的任何应用程序访问?
它能正常工作…问题是我将其设置为Web Project,而不是Oracle Enterprise Edition for Eclipse中的Java EE Utility Project。
作为一个Web项目,它将.class文件放入WEB-INF / classes而不是APP-INF中。
另外,需要将error.properties放入我的实际域中。
C:\ Oracle \中间件\ user_projects \ domains \ MyDomain
关于我自己的问题:
是否有默认目录或简单的配置区域,WebLogic会加载可在WebLogic中运行的任何应用程序访问的属性文件?
如果未设置-Dweblogic.ext.dirs,则默认为$ DOMAIN / lib; $ WL_HOME / common / lib / ext; $ WL_HOME / server / lib / ext
因此,如果将error.properties存储在$ DOMAIN / lib中,它将位于CLASSPATH上,并且应该能够使用getResourceAsStream(“ error.properties”)加载它。