2015-06-12 45 views
1

我已經搜索了幾天,無法進一步。 我想通過Web控制檯爲我的Wildfly 9服務器分配一個MySQL數據源。 如果我添加資源,我會在測試資源時出錯,這是由於wildfly 9中的一個bug造成的,該資源創建的最大池大小爲0的資源。 所以我自己編輯它,一切看起來都很好。 現在,當我嘗試在我的webapp中查找資源時,它只是一個經典的生成一些json數據的servlet應用程序,我得到一個錯誤。 javax.naming.NameNotFoundException。 資源的JNDI名稱是:java的:/ MySQLDS通過Web控制檯向wildfly添加數據源

這是通過WEB管理方式生成的XML:

<datasource jta="true" jndi-name="java:/MySQLDS" pool-name="MySQLDS" enabled="true" use-ccm="true" statistics-enabled="false"> 
    <connection-url>jdbc:mysql://ip:3306/test</connection-url> 
    <driver-class>com.mysql.jdbc.Driver</driver-class> 
    <driver>mysql</driver> 
    <pool> 
     <min-pool-size>0</min-pool-size> 
     <initial-pool-size>0</initial-pool-size> 
     <max-pool-size>20</max-pool-size> 
     <allow-multiple-users>false</allow-multiple-users> 
    </pool> 
    <security> 
     <user-name>user</user-name> 
     <password>password</password> 
    </security> 
    <validation> 
     <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/> 
     <validate-on-match>false</validate-on-match> 
     <background-validation>true</background-validation> 
     <use-fast-fail>false</use-fast-fail> 
     <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/> 
    </validation> 
    <timeout> 
     <set-tx-query-timeout>false</set-tx-query-timeout> 
     <blocking-timeout-millis>0</blocking-timeout-millis> 
     <idle-timeout-minutes>0</idle-timeout-minutes> 
     <query-timeout>0</query-timeout> 
     <use-try-lock>0</use-try-lock> 
     <allocation-retry>0</allocation-retry> 
     <allocation-retry-wait-millis>0</allocation-retry-wait-millis> 
    </timeout> 
    <statement> 
     <share-prepared-statements>false</share-prepared-statements> 
    </statement> 
</datasource> 

在我的應用我有管理我的連接一個HashMap中的各種類原因。

public class DBConnection { 

    static { 
     try { 
      context = new InitialContext(); 
     } catch (NamingException e) { 
      e.printStackTrace(); 
     } 
    } 

    private static InitialContext      context; 

    /** 
    * JNDI Lookup cache 
    */ 
    private static final HashMap<String, DataSource> connectionCache = new HashMap<String, DataSource>(); 

    private DBConnection() { 
    } 

    public static Connection getConnection(String shema) { 
     DataSource ds = connectionCache.get(shema); 
     if (ds == null) { 
      try { 
       ds = (DataSource) context.lookup("java:/" + shema); 
      } catch (NamingException e) { 
       e.printStackTrace(); 
      } 
      connectionCache.put(shema, ds); 
     } 
     try { 
      return ds.getConnection(); 
     } catch (SQLException e) { 
      e.printStackTrace(); 
     } 
     return null; 
    } 
} 

這產生了上述錯誤。

現在奇怪的部分: 我從Web控制檯刪除了資源,並通過我的WEB-INF文件夾中的* -ds.xml文件添加了完全相同的資源,它的工作原理!

<datasources xmlns="http://www.jboss.org/ironjacamar/schema"> 
    <datasource jndi-name="java:/MySQLDS" pool-name="MySQLPOOL"> 
     <connection-url>jdbc:mysql://ip:3306/test</connection-url> 
     <driver>mysql</driver> 
     <driver-class>com.mysql.jdbc.Driver</driver-class> 
     <security> 
      <user-name>user</user-name> 
      <password>password</password> 
     </security> 
    </datasource> 
</datasources> 

問題是如何通過Web控制檯添加資源並在我的應用程序中查找? 爲什麼我能夠找到資源,如果我通過XML添加資源,但不是通過Web控制檯?

回答

1

好吧,現在我感覺遲鈍..

我只是不得不重新加載服務器配置。 我雖然只是添加資源就足夠了,你準備好了!

在Wildfly內部的單個頁面上,它表示必須重新加載配置。所以我做了,現在一切正常。

對不起,轉儲。

+0

這不愚蠢,它有點混亂,我也越來越「無法創建jdbc連接 - 重新加載所需」 - 但花了我一會兒才發現這個「重新加載」按鈕。 –

+0

我剛剛升級到cr2,現在網絡控制檯都搞砸了:D 現在它看起來像一個移動視圖。並且很多標籤重疊 - .- 而重新加載按鈕全部消失,這並不意味着您必須重新加載服務器。現在,所有關於你重新啓動整個服務..上帝該死的。有人有同樣的問題嗎? –

+0

歡迎來到俱樂部:http://stackoverflow.com/questions/30803655/wildfly-9-console-changed-its-look-and-feel/30846127#30846127 –

1

這是我的數據源,它工作正常(通過Web控制檯創建)。

  <datasource jta="true" jndi-name="java:/jdbc/NotesUsersDS" pool-name="NotesUsersDS" enabled="true" use-ccm="true" statistics-enabled="true"> 
       <connection-url>jdbc:mysql://localhost:3306/users?autoReconnect=true&amp;amp;useUnicode=true&amp;amp;characterEncoding=utf8&amp;amp;characterSetResults=utf8&amp;amp;connectionCollation=utf8_unicode_ci;useLegacyDatetimeCode=false</connection-url> 
       <driver-class>com.mysql.jdbc.Driver</driver-class> 
       <driver>mysql-connector-java-5.1.35.jar_com.mysql.jdbc.Driver_5_1</driver> 
       <transaction-isolation>TRANSACTION_READ_UNCOMMITTED</transaction-isolation> 
       <pool> 
        <min-pool-size>1</min-pool-size> 
        <initial-pool-size>0</initial-pool-size> 
        <max-pool-size>256</max-pool-size> 
        <allow-multiple-users>false</allow-multiple-users> 
       </pool> 
       <security> 
        <user-name>users_user</user-name> 
        <password>my_password</password> 
       </security> 
       <validation> 
        <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/> 
        <validate-on-match>false</validate-on-match> 
        <background-validation>true</background-validation> 
        <use-fast-fail>false</use-fast-fail> 
        <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/> 
       </validation> 
       <timeout> 
        <set-tx-query-timeout>false</set-tx-query-timeout> 
        <blocking-timeout-millis>0</blocking-timeout-millis> 
        <idle-timeout-minutes>0</idle-timeout-minutes> 
        <query-timeout>0</query-timeout> 
        <use-try-lock>0</use-try-lock> 
        <allocation-retry>0</allocation-retry> 
        <allocation-retry-wait-millis>0</allocation-retry-wait-millis> 
       </timeout> 
       <statement> 
        <track-statements>true</track-statements> 
        <prepared-statement-cache-size>128</prepared-statement-cache-size> 
        <share-prepared-statements>true</share-prepared-statements> 
       </statement> 
      </datasource>