Nullpointer读取属性 Web 逻辑服务器时的异常



我在Weblogic 12.2.1中遇到了这个问题: 从检测到问题的日志中提取 [来自服务器的日志]

####<06/12/2019 06:01:31 PM COT> <Info> <Deployer> <LIM-4WZN2X2> <AdminServer> <[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <ffc7c770-2d51-4047-b19f-51eb060c58fa-0000000a> <1575673291126> <[severity-value: 64] [rid: 0] [partition-id: 0] [partition-name: DOMAIN] > <BEA-149060> <Module demo-resource-1.0.0.war of application demo-resource-1.0.0 successfully transitioned from STATE_PREPARED to STATE_ADMIN on server AdminServer.> 
####<06/12/2019 06:01:31 PM COT> <Error> <HTTP> <LIM-4WZN2X2> <AdminServer> <[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <ffc7c770-2d51-4047-b19f-51eb060c58fa-0000000a> <1575673291485> <[severity-value: 8] [rid: 0] [partition-id: 0] [partition-name: DOMAIN] > <BEA-101216> <Servlet: "pe.demo.app.resource.conf.ApplicationConfig" failed to preload on startup in Web application: "demo-resource-1.0.0.war".
pe.demo.app.resource.exception.GeneralRuntimeException: Cannot read .properties file 
at pe.demo.app.resource.conf.ApplicationConfig.readProperties(ApplicationConfig.java:78)
at pe.demo.app.resource.conf.ApplicationConfig.getProperties(ApplicationConfig.java:45)
at org.glassfish.jersey.server.ResourceConfig$WrappingResourceConfig.mergeApplications(ResourceConfig.java:1140)
at org.glassfish.jersey.server.ResourceConfig$WrappingResourceConfig._setApplication(ResourceConfig.java:1077)
at org.glassfish.jersey.server.ResourceConfig.setApplication(ResourceConfig.java:1029)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:342)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:390)

我调用属性文件的代码是使用 JAXRS 的 Java 代码:

package pe.demo.app.resource.conf;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;
import javax.inject.Singleton;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import pe.demo.app.common.exception.ProviderExceptionMapper;
import pe.demo.app.common.property.Constantes;
import pe.demo.app.common.resource.exception.GeneralRuntimeException;
import pe.demo.app.resource.DemoResource;
@Singleton
@ApplicationPath( "api" )
public class ApplicationConfig extends Application{
private static final String NAME_DIRECTORY       = "my-directory";
private static final String NAME_VARIABLE        = "variable-weblogic-properties-root";
private static final String NAME_FILE            = ".properties";
@Override
public Set<Class<?>> getClasses(){
Set<Class<?>> resources = new java.util.HashSet<Class<?>>();
resources.add( DemoResource.class );
resources.add( ProviderExceptionMapper.class );
resources.add( com.wordnik.swagger.jaxrs.listing.ApiListingResource.class );
resources.add( com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider.class );
resources.add( com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON.class );
resources.add( com.wordnik.swagger.jaxrs.listing.ResourceListingProvider.class );
return resources;
}
public Map<String, Object> getProperties(){
String nombrePropertieExterno = NAME_FILE;
Map<String, Object> dataProperties = new HashMap<String, Object>();
dataProperties.putAll( readProperties( nombrePropertieExterno, false ) );
return dataProperties;
}
private Map<String, Object> readProperties( String fileInClasspath, Boolean interno ){
System.out.println( "method:[readProperties], nombre de properties recibido:-->" + fileInClasspath );
InputStream is = null;
String urlServer = "";
try{
if( interno ){
is = this.getClass().getClassLoader().getResourceAsStream( fileInClasspath );
}
else{
String filePropertiesRoot = System.getProperty( NAME_VARIABLE );
urlServer = filePropertiesRoot + NAME_DIRECTORY + File.separator + fileInClasspath;
is = new FileInputStream( urlServer );
}
Map<String, Object> map = new HashMap<String, Object>();
Properties properties = new Properties();
properties.load( is );
map.putAll(
properties.entrySet().stream().collect( Collectors.toMap( e -> e.getKey().toString(), e -> e.getValue() ) ) );
is.close();
return map;
}
catch( Exception e ){
throw new GeneralRuntimeException( " Cannot read file " + fileInClasspath, e );
}
}
}

当战争应用程序部署在Weblogic服务器中时,日志中显示的错误发生了。但是当我在自己的机器 Weblogic 12.2.1 服务器中部署时,工作正常。

错误日志中检测问题的行是:

Caused By: java.io.FileNotFoundException: nullmy-directory/.properties (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)

这个用于提取我所有属性的根目录的 say 变量为 null,无法为我的文件 .properties 创建所有路径。

--> 另一个应用程序使用相同的方法为Weblogic环境提取此变量,并且未发生此错误

为了尝试在我的机器中重新创建错误,我只是这样做: (在创建文件输入流的行中:

// is = new FileInputStream( urlServer );
//change for :
is = this.getClass().getClassLoader().getResourceAsStream( urlServer );

现在我在本地 Weblogic 服务器中的错误就像 null,但不同,因为 en dev environmet null 用于 weblogic 变量,对于此更改,null 用于所有路径:(。

该应用程序工作正常,但是有时在重新部署我的战争应用程序时重新启动服务器时会发生错误。 但是当使用应用程序时,从属性返回值。

我认为使用 JAXRS 时 REST 应用程序的生命周期,但我是 JavaEE 的新手。

感谢您的帮助,对不起我的英语

好吧,在创建具有类似配置的项目以免更改在其他组件上执行的测试之后,解决方案是:从 Weblogic 控制台中删除该组件,重新部署整个组件(war 应用程序(。

最新更新