4
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Weblogicで各Webアプリのクラスローダでロードされたクラスを優先させる方法

Last updated at Posted at 2013-09-05

ハマったのでメモ。

はじめに

アプリケーションサーバのようにクラスローダに親子がある環境では、親でロードされたクラスが優先されてしまい、各アプリケーションに配置したクラスが実行時に利用できないといった事が起こる。

起こりえる問題

例えば、 Weblogic 10.3.3 では、 Weblogic 自身が apache-commons-lang の ver 2.1 をロードしている。
この Weblogic に、 apache-commons-lang の ver 2.6 を使用した以下のような実装を持つ Web アプリを配備したとする。

Webアプリの実装(一部)
logger.info("parameter : " + StringUtils.join(paramList, ","));

WEB-INF/lib にしっかりと jar を配置していても、この Web アプリは実行時に StringUtils.join(paramList, ",") の部分で NoSuchMethodError が発生してしまう。

これは、 Weblogic が既にロードしていた ver 2.1 の StringUtils に join(Collection, String) が存在しないのが原因(当該メソッドは ver 2.3 から実装されている)。

対処方法

このエラーを防ぐには、各 Web アプリでロードされたクラスを優先するように設定する必要がある。

Weblogic では、 WEB-INF フォルダの直下に weblogic.xml という XML ファイルを配置し、 prefer-web-inf-classestrue を指定すればいい。

weblogic.xml
<?xml version="1.0" encoding="UTF-8" ?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
  ...
  <container-descriptor>
    <prefer-web-inf-classes>true</prefer-web-inf-classes>
  </container-descriptor>
  ...
</weblogic-web-app>

prefer-web-inf-classestrue を指定すると、 WEB-INF 以下のクラスが優先して使用されるようになり、前述の問題が発生しなくなる。

特定のパッケージだけを優先する方法もあるっぽい。

参考

4
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?