簡體   English   中英

grails:使用tomcat和jndi時找不到表

[英]grails: table not found when using tomcat and jndi

使用dataSource.groovy可以正常工作。 當我轉戰使用tomcat上的JNDI時,我得到:

2014-04-14 12:16:19,244 [localhost-startStop-1] ERROR util.JDBCExceptionReporter  - Table "REPORT" not found; 
SQL statement: select [...] from report this_ where this_.name=? [42102-173]

看起來好像它已連接到DB正常,但無法看到表,它是集市。

在DataSource.groovy中工作的配置(當我不使用tomcat運行時):

  development2 {
    dataSource {
        url = 'jdbc:mysql://localhost/rep'
        username = "root"
        password = ""
        dialect = org.hibernate.dialect.MySQL5InnoDBDialect
        pooled = true
        jmxExport = true
    dbCreate = "update"
        driverClassName = "com.mysql.jdbc.Driver"
        properties {
            maxActive = -1
            minEvictableIdleTimeMillis=1800000
            timeBetweenEvictionRunsMillis=1800000
            numTestsPerEvictionRun=3
            testOnBorrow=true
            testWhileIdle=true
            testOnReturn=true
            validationQuery="SELECT 1"
        }
    }

無法在DataSource.groovy中使用jndi配置:

localtomcat {
    dataSouce {
        dbCreate = "update"
        jndiName = "java:comp/env/repDB"
    }

Tomcat 7中的context.xml:

<Resource name="repDB" auth="Container" type="javax.sql.DataSource"
    maxActive="100" maxIdle="5" maxWait="10000"
    username="root" password="" driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/rep"/>

我也試過這個:

localtomcat {
    dataSouce {
        dialect = org.hibernate.dialect.MySQL5InnoDBDialect
        driverClassName = "com.mysql.jdbc.Driver"
        dbCreate = "update"
        jndiName = "java:comp/env/repDB"
    }

為什么可以看到數據庫但看不到表的任何想法(存在,有數據並且不需要更新)

有些帖子說您需要web.xml中的某些內容,有些則說您不需要。 我那里什么都沒有。

root用戶對所有內容都具有全局權限。

我正在建立戰爭:

grails -Dgrails.env=localtomcat war

更新:我應該補充一點,實際上每個環境都有兩個數據源,一個是grails使用的,另一個是我剛剛查詢的(即報告服務器)。 在tomcat之外可以正常工作。 主數據源稱為“數據源”,定義如下。 另一個稱為datasource_reporting。 所以我的DataSource.groovy看起來像這樣:

dataSource {
     pooled = true
     jmxExport = true
}

dataSource_reporting {
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
pooled = true
jmxExport = true
driverClassName = "com.mysql.jdbc.Driver"
properties {
    maxActive = -1
    minEvictableIdleTimeMillis=1800000
    timeBetweenEvictionRunsMillis=1800000
    numTestsPerEvictionRun=3
    testOnBorrow=true
    testWhileIdle=true
    testOnReturn=true
    validationQuery="SELECT 1"
  }
}

環境{生產{dataSouce {方言= org.hibernate.dialect.MySQL5InnoDBDialect driverClassName =“ com.mysql.jdbc.Driver” dbCreate =“ update” jndiName =“ java:comp / env / rep”}

    dataSource_reporting {
        dialect = org.hibernate.dialect.MySQL5InnoDBDialect
        driverClassName = "com.mysql.jdbc.Driver"
            jndiName = "java:comp/env/reporting"
    }
}

然后我在tomcat的context.xml中有兩個對應的整體:

<Resource name="reporting" auth="Container" type="javax.sql.DataSource"
    maxActive="20" maxIdle="5" maxWait="20000"
    username="someuser" password="somepass" driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://xx.xx.xx.xx:3306/somemaindb"/>

<Resource name="rep" auth="Container" type="javax.sql.DataSource"
    maxActive="100" maxIdle="5" maxWait="10000"
    username="root" password="" driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost/rep"/>

也許grails + tomcat無法處理兩個數據庫連接?

rep數據庫具有其抱怨缺失的報告表,並且根用戶的權限是上帝。 也許grails試圖在錯誤的數據庫上打開reprot表?

我們在server.xml中有這些文件,嘗試尋找該塊並將其放在GlobalNamingResources中

GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
        -->
<Resource name="repDB" auth="Container" type="javax.sql.DataSource"
    maxActive="100" maxIdle="5" maxWait="10000"
    username="root" password="" driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/rep"/>

    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

好。 我找到了答案。 正如人們所期望的那樣,這是非常愚蠢的。

我在DataSource.groovy文件中花費了datasSource dataSouce

因此表讀取錯誤=未定義dataSource。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM