---
title: "Weblogic部署CAS3.5问题解决方案"
author: "雨辰RainTime"
date: "2014-05-19T22:48:04Z"
tags: []
categories: ["开源软件"]
slug: "weblogic-cas3-5"
draft: false
lastmod: "2014-05-19T22:49:34Z"
id: 2068456
url: "https://jcbay.iteye.com/blog/2068456"
---

webLogic版本：10.3.6.0

cas服务端版本：3.5.2.1

**事件背景：**

部署一套SSO环境，选用CAS最新版做为服务端，在开发阶段选用Tomcat6做为应用容器未出现任何问题，业务功能整合完毕后准备将CAS服务端移植到weblogic环境下，然后问题出现了。

**问题列表：**

在整个部署过程中，主要遇到两个问题

一：找不到log4j.xml文件

异常信息摘录如下：

```
Caused By: java.io.FileNotFoundException: class path resource [log4j.xml] cannot be resolved to absolute file path because it does not reside in the file system: zip:/home/weblogic/Oracle/Middleware/user_projects/domains/yourdomain/servers/AdminServer/tmp/_WL_user/authServer2/gksqn0/war/WEB-INF/lib/_wl_cls_gen.jar!/log4j.xml
```

 

 

二：jsp编译失败

异常信息摘录如下：

```
Caused By: javax.servlet.ServletException: weblogic.servlet.jsp.CompilationException: Failed to compile JSP /WEB-INF/view/jsp/default/ui/casLoginView.jsp
casLoginView.jsp:1:1: The validator class: "org.apache.taglibs.standard.tlv.JstlCoreTLV" has failed with the following exception: "java.lang.ClassCastException: weblogic.xml.jaxp.RegistrySAXParserFactory cannot be cast to javax.xml.parsers.SAXParserFactory".
<jsp:directive.include file="includes/top.jsp" />
^-----------------------------------------------^
```

 

**解决方案：**

**问题一：**

对于第一个问题的出现，网上也是说什么的都有，反正就是找不到Log4j的文件从而初始化失败。

解决方案有两种：

1：使用目录方式进行应用的部署

如果使用WAR包部署的话，会出现这种错误，换成目录的方式进行部署就没有这个问题了。

2：改变Log4j的初始化方式

如果非得使用WAR包进行部署的话，就不能使用CAS默认的Spring方式来初始化Log4j的配置文件了，可以使用Servlet的方式将Log4j的配置文件进行初始化，我的servlet代码：

```
/**
 * 自定义LOG4J启动类
 * cas打成WAR包部署到weblogic上因找不到log4j.xml文件而出错
 * @author zz
 */
public class Log4jInit extends HttpServlet {
 public void init() throws ServletException {
  String file = getInitParameter("log4j");
  System.out.println("...........log4j start");
  if(null != file) {
   Properties ps=new Properties();
    try {
    ps.load(getServletContext().getResourceAsStream(file));
    } catch (IOException e) {
    e.printStackTrace();
    }
    PropertyConfigurator.configure(ps);
  }
 }
}
```

 然后配置到web.xml中，并设置优先加载。

```
<servlet>
  <servlet-name>log4jLoader</servlet-name>
  <servlet-class>com.zz.util.Log4jInit</servlet-class>     
  <init-param>
  <param-name>log4j</param-name>
  <param-value>/WEB-INF/log4j.properties</param-value>	</init-param> 
  <load-on-startup>0</load-on-startup>
</servlet>
```

 这里我将默认的log4j.xml转换成了log4j.properties文件。

然后将CAS默认的初始化方式进行屏蔽：修改WEB-INF/spring-configuration/log4jConfiguration.xml文件，将初始化的bean注释掉：

```
<!-- 
<bean id="log4jInitialization" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
  <property name="targetClass" value="org.springframework.util.Log4jConfigurer"/>
  <property name="targetMethod" value="initLogging"/>
  <property name="arguments">
    <list>
      <value>${log4j.config.location:classpath:log4j.xml}</value>
      <value>${log4j.refresh.interval:60000}</value>
    </list>
  </property>
</bean>
-->
```

 至此，针对找不到log4j配置文件的问题得以解决，为了方便以后的部署工作，我采用的是第二种解决方案，也就是WAR包形式进行部署。

**问题二：**

对于第二个问题，解决的时候是走了不少弯路，主要还是网上的解决方案太操蛋了。

该问题的意思是说解析jsp文件出错了，网上的解决方案基本比较统一，如：加个weblogic.xml优先加载项目JAR，删除xml-api.jar。

但经过试验发现，如果删除xml-api.jar，在启动APP的时候就会出错，提示找不到：org.w3c.dom.ElementTraversal

经过各种测试，在我的项目里，解决方案就是将项目中的xml-api.jar移到weblogic下domain的lib中，注意，是移动，而不是复制，

目录：/home/weblogic/Oracle/Middleware/user\_projects/domains/yourdomain/lib。

在解决该问题时，记得时常删除缓存文件，目录：

/home/weblogic/Oracle/Middleware/user\_projects/domains/yourdomain/servers/AdminServer/tmp/\_WL\_user/