weblogic下部署应用时slf4j与logbak冲突的解决办法

时间:2024-09-18 18:02:56

今天在weblogic上部署一个使用logback的应用时,报错如下:

java.lang.IllegalArgumentException: Invalid 'logbackConfigLocation' parameter: /opt/app/Oracle/Middleware/user_projects/domains/base_domain/servers/Server7005/tmp/_WL_user/acc_service_ca/bk1axn/war/WEB-INF/lib/_wl_cls_gen.jar!/logback.xml

网上搜索了一翻,大致原因是weblogic已经自带了slf4j的模块,与应用中的logback冲突,按照官网 https://community.oracle.com/thread/3525130?start=0&tstart=0 的做法,在WEB-INF下放一个名为weblogic.xml的文件,参考以下内容:

 <?xml version="1.0" encoding="UTF-8"?>

 <weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90">
<session-descriptor>
<cookie-path>/</cookie-path>
</session-descriptor> <jsp-descriptor>
<keepgenerated>true</keepgenerated>
<page-check-seconds>60</page-check-seconds>
<precompile>true</precompile>
<precompile-continue>true</precompile-continue>
</jsp-descriptor> <container-descriptor>
<optimistic-serialization>true</optimistic-serialization>
<prefer-web-inf-classes>false</prefer-web-inf-classes>
<show-archived-real-path-enabled>true</show-archived-real-path-enabled>
<prefer-application-packages>
<package-name>org.slf4j</package-name>
</prefer-application-packages> </container-descriptor>
</weblogic-web-app>

关键是17-21这几行,在weblogic 10.3.3版本上验证通过