在Log4j的构建阶段,我得到了下面的错误。它说没有为配置找到这样的方法(FileInputSteam)。
下面是错误的全部内容。
任务:编译Task失败
E:\GadleDemoProj\src\main\java\com\hal\brands\helper\Logger\LoggerHelper.java:28: error: no suitable method found for configure(FileInputStream)
PropertyConfigurator.configure(inputStream);
^
method PropertyConfigurator.configure(Properties) is not applicable
(argument mismatch; FileInputStream cannot be converted to Properties)
method PropertyConfigurator.configure(String) is not applicable
(argument mismatch; FileInputStream cannot be converted to String)
method PropertyConfigurator.configure(URL) is not applicable
(argument mismatch; FileInputStream cannot be converted to URL)我的Logger类如下所示:
public class LoggerHelper {
private static boolean root = false;
public static Logger getLogger(Class clas) {
if(root)
return Logger.getLogger(clas);
/*PropertyConfigurator.configure(ResourceHelper
.getResourcePath("configfile/log4j.properties"));*/
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(System.getProperty("user.dir")+"\\src\\main\\resources\\configFile\\log4j.properties");
PropertyConfigurator.configure(inputStream);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
root = true;
return Logger.getLogger(clas);
}
}发布于 2020-09-17 15:12:52
更新代码如下:
public class LoggerHelper {
private static boolean root = false;
public static Logger getLogger(Class clas) {
if(root)
return Logger.getLogger(clas);
/*PropertyConfigurator.configure(ResourceHelper
.getResourcePath("configfile/log4j.properties"));*/
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(System.getProperty("user.dir")+"\\src\\main\\resources\\configFile\\log4j.properties");
Properties properties = new Properties();
properties.load(inputStream);
PropertyConfigurator.configure(properties);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
root = true;
return Logger.getLogger(clas);
}
}https://stackoverflow.com/questions/63940801
复制相似问题