Java Wildfly 10 无法连接数据源:连接无效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40538343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:47:01  来源:igfitidea点击:

Wildfly 10 can't connect datasource: invalid connection

javajakarta-eejdbcdatasourcewildfly

提问by Freki

Problem

问题

I'm trying test my connection and it keeps giving me the same error while at first sight I can't see what I did wrong. Maybe I'm overlooking something...

我正在尝试测试我的连接,它不断给我同样的错误,而乍一看我看不出我做错了什么。也许我忽略了一些东西......

Error

错误

    nexpected HTTP response: 500

    Request
    {
       "address" => [
            ("subsystem" => "datasources"),
            ("data-source" => "ProjectenDS")
        ],
        "operation" => "test-connection-in-pool"
    }

    Response

    Internal Server Error
    {
        "outcome" => "failed",
        "failure-description" => "WFLYJCA0040: failed to invoke operation: WFLYJCA0047: Connection is not valid",
        "rolled-back" => true
    }



Standalone-full.xml

独立-full.xml

    <subsystem xmlns="urn:jboss:domain:datasources:4.0">
                <datasources>
                    <datasource jta="true" jndi-name="java:/ProjectenDS" pool-name="ProjectenDS" enabled="true" use-ccm="true">
                        <connection-url>jdbc:mysql://localhost:3306/projecten3db</connection-url>
                <driver-class>com.mysql.jdbc.Driver</driver-class>
                <driver>mysql-connector-java-5.1.40-bin.jar_com.mysql.jdbc.Driver_5_1</driver>
                <pool>
                    <min-pool-size>10</min-pool-size>
                    <initial-pool-size>11</initial-pool-size>
                    <max-pool-size>100</max-pool-size>
                </pool>
                <security>
                    <user-name>projecten</user-name>
                    <password>projecten</password>
                </security>
                <validation>
                    <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
                    <background-validation>true</background-validation>
                    <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
                </validation>
            </datasource>
        </datasources>
    </subsystem>

回答by user2543120

The exception you have is generic.

你的例外是通用的。

Check on {WILDFLY_HOME}/standalone/log/server.log

检查 {WILDFLY_HOME}/standalone/log/server.log

You can use tail -f server.logwhile you test on the web console.

您可以tail -f server.log在 Web 控制台上测试时使用。

This will give you the right error to work on.

这会给你正确的错误来处理。

回答by rodrigomelo

I solved this error by reducing pool size and set prefill attribute to false on datasource settings.

我通过减少池大小并在数据源设置上将 prefill 属性设置为 false 来解决此错误。

<pool>
   <min-pool-size>5</min-pool-size>
   <max-pool-size>10</max-pool-size>
   <prefill>false</prefill>
   <use-strict-min>false</use-strict-min>
   <flush-strategy>IdleConnections</flush-strategy>
</pool>

回答by Dima Fomin

We had such error on MS SQL when our user was not mapped to requested database

当我们的用户没有映射到请求的数据库时,我们在 MS SQL 上出现了这样的错误

回答by Prefijo Sustantivo

If your datasource is not XA, open standalone.xml and remove the datasource-classproperty from your datasource definition. Wildfly adds it even if you don't specify it whe you create the datasource.

如果您的数据源不是 XA,请打开 standalone.xml 并datasource-class从您的数据源定义中删除该属性。即使您在创建数据源时未指定它,Wildfly 也会添加它。

You may have to restart the server to see it working.

您可能必须重新启动服务器才能看到它工作。