gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 23:37:45 25 4
gpt4 key购买 nike

使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com