BasicDataSourceが原因でWebSphereでjava.util.ConcurrentModificationExceptionが発生する
問題
Springでは、データソースを「org.apache.commons.dbcp.BasicDataSource」として宣言します。 WebSphereにデプロイすると、すべてが完全に機能します。
ファイル:spring-datasource.xml
classpath:config/database/database.properties
ただし、WebSphereでWebアプリケーションを再起動すると、次の例外が発生します。
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSource' defined in class path resource
[config/database/spring/spring-datasource.xml]: Instantiation of bean failed;
......
Caused by: java.lang.ExceptionInInitializerError
at java.lang.J9VMInternals.initialize(J9VMInternals.java:222)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
... 114 more
Caused by: java.util.ConcurrentModificationException
at java.util.AbstractList$SimpleListIterator.next(Unknown Source)
at java.sql.DriverManager.getDrivers(Unknown Source)
at org.apache.commons.dbcp.BasicDataSource.(BasicDataSource.java:57)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
... 121 more
データソース(BasicDataSource)が「java.util.ConcurrentModificationException」を引き起こしているように見えます。
溶液
「org.apache.commons.dbcp.BasicDataSource」ではなく、WebSphereデータソースを使用する必要があります。 これを修正するには、WebSphereデータソースを登録し、「jdbc/anythingDS」のようなjndi名を入力します。 Springでは、次のようにjndiデータソースを宣言します。
ファイル:spring-datasource.xml
WebSphere開発では、WebSphereの方法に従う必要があります。