tomcat - grails:使用 tomcat 和 jndi 时找不到表

标签 tomcat grails datasource

使用 dataSource.groovy 是可行的。当我在 war 中切换到在 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]

这看起来连接到数据库没问题,但是看不到表,这是集市。

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 用户拥有全局权限。

我是这样构建 war 的:

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"
  }
}

环境{ 生产{ 数据源{ 方言 = org.hibernate.dialect.MySQL5InnoDBDialect driverClassName = "com.mysql.jdbc.Driver" dbCreate = "更新" 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 DB 有它提示缺少的报告表,而 root 用户的权限是上帝。也许 grails 正试图在错误的数据库上打开 reprot 表?

最佳答案

我们的 server.xml 中有这些,尝试查找此 block 并将其放入 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>

关于tomcat - grails:使用 tomcat 和 jndi 时找不到表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23057987/

相关文章:

tomcat - 如果我尝试使用 servlet 发送电子邮件,为什么无法解析本地主机

java - Crystal Report - 使用 ResultSet 的主报表中的子报表

ios - UIPageViewController -presentationCount 未触发

java - 数据库中的总 session 数与 websphere 连接池中设置的不一样

tomcat - tomcat 7 的 settings.xml 在哪里?

JSF Tomcat 容器管理身份验证和附加登录按钮

maven - IntelliJ 无法在本地主机 :1099 ping 服务器

grails - 特定域的HQL查询是否应特定于该域?

multithreading - 如何优化Grails构建和测试执行速度?

grails - 从过滤器返回false时使URLMapping失败?