Java – migrate to Tomcat 8: instancealreadyexistsexception data source

I have a question about the context configuration in Tomcat 8 I migrated the project from Tomcat 7 to Tomcat 8, and there is an abnormal problem: if there is no change in the configuration, I find an error:

"2015-02-03 12:05:48,310 FIRST_ADMIN ERROR web.context.ContextLoader:331 
-> Context initialization Failed org.springframework.jmx.export.UnableToRegisterMBeanException: 
    Unable to register MBean [org.apache.tomcat.dbcp.dbcp2.BasicDataSource@434990dd]
     with key 'dataSource'; nested exception is 
    javax.management.InstanceAlreadyExistsException:  
    Catalina:type=DataSource,host=localhost,context=/first-
    admin,class=javax.sql.DataSource,name="jdbc/datasource/first"

Part of the context:

<Resource name="jdbc/datasource/first"
              auth="Container"
              type="javax.sql.DataSource"
              poolPreparedStatements="true"
              initialSize="25"
              maxActive="100"
              maxIdle="100"
              minIdle="25"
              username="us"
              password="pa"
              driverClassName="com.MysqL.jdbc.Driver"
              validationQuery="select 1"
              testOnBorrow="true"
          url="jdbc:MysqL://localhost:3306/firstproject?useUnicode=true&amp;characterEncoding=UTF-8&amp;profilesql=false&amp;autoSlowLog=false&amp;slowQueryThresholdMillis=100&amp;autoReconnect=true"/>

Therefore, it has no problem in Tomcat 7 In Tomcat 8, I can solve this problem in two ways:

>Adding resources: Singleton = "false"; > By adding to the asset: Factory = "org. Apache. Tomcat. JDBC. Pool. Datasourcefactory"

If I understand that Tomcat creates data sources for my application and JMX, but in Tomcat 7, it is a single object, and in Tomcat 8, it must be different So my question is why did this happen? I can't find any information about this change in the document What's interesting to me is better: create a single data source (I think so), or create several data sources through a factory

Solution

I have the same error and fix it by adding registration = "ignoreexisting" to the MBean export section:

<context:mbean-export server="mbeanServer" default-domain="mydomain" registration="ignoreExisting" />
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>