如何将 Grails war 部署到 tomcat
How to deploy a Grails war to tomcat
我想部署到 Tomcat 服务器 8 的 WAR 文件有问题。
tomcat 服务器使用默认值安装(仅更改了用户和密码)。
当我部署 WAR 文件时,我从 Catalina.out 日志中得到这个输出:
Configuring Spring Security Core ...
... finished configuring Spring Security Core
Configuring Spring Security REST ...
... finished configuring Spring Security REST
2015-04-06 13:37:37,345 [http-nio-8080-exec-2] ERROR context.GrailsContextLoaderListener - Error initializing the application: Error creat$
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of$
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve refe$
... 5 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init meth$
... 5 more
Caused by: org.hibernate.MappingException: Missing type or column for column[descripciono_descripciones] on domain[Ejercicios] referencing[$
... 5 more
2015-04-06 13:37:37,348 [http-nio-8080-exec-2] ERROR context.GrailsContextLoaderListener - Error initializing Grails: Error creating bean $
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of$
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve refe$
... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init meth$
... 3 more
Caused by: org.hibernate.MappingException: Missing type or column for column[descripciono_descripciones] on domain[Ejercicios] referencing[$
... 3 more
2015-04-06 13:38:57,516 [http-nio-8080-exec-8] ERROR context.GrailsContextLoaderListener - Error initializing Grails: Error creating bean $
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of$
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve refe$
... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init meth$
... 3 more
Caused by: org.hibernate.MappingException: Missing type or column for column[descripciono_descripciones] on domain[Ejercicios] referencing[$
... 3 more
06-Apr-2015 13:38:57.517 SEVERE [http-nio-8080-exec-8] org.apache.catalina.core.StandardContext.startInternal Error listenerStart
06-Apr-2015 13:38:57.518 SEVERE [http-nio-8080-exec-8] org.apache.catalina.core.StandardContext.startInternal Context [/backend-gimnasio-0.$
06-Apr-2015 13:38:57.540 WARNING [http-nio-8080-exec-8] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web applic$
06-Apr-2015 13:38:57.540 WARNING [http-nio-8080-exec-8] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web app$
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)
com.mysql.jdbc.NonRegisteringDriver.run(NonRegisteringDriver.java:93)
我的猜测是 MySQL 连接有问题,但我真的不知道我应该在哪里指定连接字符串或类似的东西......数据库是在服务器上创建的,并且 Grails 中的数据源指向该数据库。
编辑:
<?xml version="1.0" encoding="ISO-8859-1"?>
<webapps>
<Context path="/backend-gimnasio" docBase="webapps/backend-gimnasio" debug="0" reloadable="true">
<!-- Replace path and docBase and etc. with your applications settings.
This file assumes that this file is named apps-myapp.xml and is
located under Tomcats configuration directory. It is also assumed that
the application which is going to use MyConnection JDBC connection is
called myapp and is accessed as http://yourdomain.tld/myapp and is
located under Tomcats webapps directory. Database name is assumed
my_database. Replace these with your actual values. -->
<!-- This is a sample XML config file for an Apache Tomcat 5.5 server to
setup MySQL Connector/J 5.1 for JDBC connectivity. Information are
derived from sources available in the Internet. -->
<!-- Resource name and ResourceParams name, must be the same and
The connection pool will be bound into JNDI with that name
Eg: "java:/comp/env/jdbc/MyConnection". Replace MyConnection in both
places with the name you want for the connection. -->
<Resource name="jdbc/MyConnection" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/MyConnection">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<!-- Don't set this higher than max_connections on your MySQL server,
usually this should be a 10 or a few 10's of connections, not
hundreds or thousands -->
<parameter>
<name>maxActive</name>
<value>10</value>
</parameter>
<!-- Just allow only as many idle connections as you require. Too much
is bad. -->
<parameter>
<name>maxIdle</name>
<value>5</value>
</parameter>
<!-- Don't use autoReconnect=true, it's going away eventually and it's a
crutch for older connection pools that couldn't test connections.
You need to decide whether your application is supposed to deal with
SQLExceptions (hint, it should), and how much of a performance
penalty you're willing to pay to ensure 'freshness' of the connection -->
<parameter>
<name>validationQuery</name>
<value>SELECT 1</value>
</parameter>
<!-- The most conservative approach is to test connections before they're
given to your application. For most applications this is okay, the
query used above is very small and takes no real server resources to
process, other than the time used to traverse the network. If you have
a high-load application you'll need to rely on something else. -->
<parameter>
<name>testOnBorrow</name>
<value>true</value>
</parameter>
<!-- Otherwise, or in addition to testOnBorrow, you can test while
connections are sitting idle -->
<parameter>
<name>testWhileIdle</name>
<value>true</value>
</parameter>
<!-- You have to set this value, otherwise even though you've asked
connections to be tested while idle,the idle evicter thread
will never run -->
<parameter>
<name>timeBetweenEvictionRunsMillis</name>
<value>10000</value>
</parameter>
<!-- Don't set this too high. A few minutes or even fraction of a minute
is sometimes okay here, it depends on your application and how much
spikey load it will see -->
<parameter>
<name>minEvictableIdleTimeMillis</name>
<value>60000</value>
</parameter>
<!-- Username and password used when connecting to MySQL. Replace myuser
and mypassword with your username/password for the database user. -->
<parameter>
<name>"username"</name>
<value>"password"</value>
</parameter>
<parameter>
<name>"username"</name>
<value>"password"</value>
</parameter>
<!-- Class name for the Connector/J driver -->
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<!-- The JDBC connection url for connecting to MySQL, notice that if
you want to pass any other MySQL-specific parameters you should
pass them here in the URL, setting them using the parameter
tags above will have no effect, you will also need to use &
to separate parameter values as the ampersand is a reserved
character in XML. Replace my_database with your database name. -->
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/gimnasioBackend</value>
</parameter>
</ResourceParams>
</Context>
</webapps>
我将上述配置添加到 Tomcat,但仍然无法连接。我开始对这个问题有点绝望了。
从堆栈跟踪中提取;
Missing type or column for column[descripciono_descripciones] on domain[Ejercicios]
如果列名与驼峰式到下划线格式的约定不匹配,那么通常会从 Hibernate 得到 MappingException
。如果是这种情况,则必须使用 column:
在 mappings
部分手动完成映射
例如,airportCode column: 'AIRPORT_CD'
修复也会解决部署问题(考虑到没有其他障碍)。
在为这个问题苦苦挣扎了一周之后,在一位同事和 Tomcat 文档的帮助下,我找到了解决方案。
配置在context.xml文件中,如下:
<Resource name="jdbc/turismoBackend" auth="Container" type="javax.sql.DataSource"
maxTotal="100" maxIdle="30" maxWaitMillis="10000"
username="youruser" password="yourpassword" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/yourdb"/>
值得注意的是,为了让 Tomcat 能够访问 MySQL,必须创建一个与 root 不同的用户,并且具有所有权限和授权选项。像这样:
CREATE USER '[yourUsername]'@'localhost' IDENTIFIED BY '[yourPassword]';
GRANT ALL PRIVILEGES TO [yourUsername]@[yourServer] IDENTIFIED BY [yourPassword] WITH GRANT OPTION;
就是这样!一切顺利 运行.
我想部署到 Tomcat 服务器 8 的 WAR 文件有问题。 tomcat 服务器使用默认值安装(仅更改了用户和密码)。 当我部署 WAR 文件时,我从 Catalina.out 日志中得到这个输出:
Configuring Spring Security Core ...
... finished configuring Spring Security Core
Configuring Spring Security REST ...
... finished configuring Spring Security REST
2015-04-06 13:37:37,345 [http-nio-8080-exec-2] ERROR context.GrailsContextLoaderListener - Error initializing the application: Error creat$
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of$
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve refe$
... 5 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init meth$
... 5 more
Caused by: org.hibernate.MappingException: Missing type or column for column[descripciono_descripciones] on domain[Ejercicios] referencing[$
... 5 more
2015-04-06 13:37:37,348 [http-nio-8080-exec-2] ERROR context.GrailsContextLoaderListener - Error initializing Grails: Error creating bean $
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of$
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve refe$
... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init meth$
... 3 more
Caused by: org.hibernate.MappingException: Missing type or column for column[descripciono_descripciones] on domain[Ejercicios] referencing[$
... 3 more
2015-04-06 13:38:57,516 [http-nio-8080-exec-8] ERROR context.GrailsContextLoaderListener - Error initializing Grails: Error creating bean $
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of$
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve refe$
... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init meth$
... 3 more
Caused by: org.hibernate.MappingException: Missing type or column for column[descripciono_descripciones] on domain[Ejercicios] referencing[$
... 3 more
06-Apr-2015 13:38:57.517 SEVERE [http-nio-8080-exec-8] org.apache.catalina.core.StandardContext.startInternal Error listenerStart
06-Apr-2015 13:38:57.518 SEVERE [http-nio-8080-exec-8] org.apache.catalina.core.StandardContext.startInternal Context [/backend-gimnasio-0.$
06-Apr-2015 13:38:57.540 WARNING [http-nio-8080-exec-8] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web applic$
06-Apr-2015 13:38:57.540 WARNING [http-nio-8080-exec-8] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web app$
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)
com.mysql.jdbc.NonRegisteringDriver.run(NonRegisteringDriver.java:93)
我的猜测是 MySQL 连接有问题,但我真的不知道我应该在哪里指定连接字符串或类似的东西......数据库是在服务器上创建的,并且 Grails 中的数据源指向该数据库。
编辑:
<?xml version="1.0" encoding="ISO-8859-1"?>
<webapps>
<Context path="/backend-gimnasio" docBase="webapps/backend-gimnasio" debug="0" reloadable="true">
<!-- Replace path and docBase and etc. with your applications settings.
This file assumes that this file is named apps-myapp.xml and is
located under Tomcats configuration directory. It is also assumed that
the application which is going to use MyConnection JDBC connection is
called myapp and is accessed as http://yourdomain.tld/myapp and is
located under Tomcats webapps directory. Database name is assumed
my_database. Replace these with your actual values. -->
<!-- This is a sample XML config file for an Apache Tomcat 5.5 server to
setup MySQL Connector/J 5.1 for JDBC connectivity. Information are
derived from sources available in the Internet. -->
<!-- Resource name and ResourceParams name, must be the same and
The connection pool will be bound into JNDI with that name
Eg: "java:/comp/env/jdbc/MyConnection". Replace MyConnection in both
places with the name you want for the connection. -->
<Resource name="jdbc/MyConnection" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/MyConnection">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<!-- Don't set this higher than max_connections on your MySQL server,
usually this should be a 10 or a few 10's of connections, not
hundreds or thousands -->
<parameter>
<name>maxActive</name>
<value>10</value>
</parameter>
<!-- Just allow only as many idle connections as you require. Too much
is bad. -->
<parameter>
<name>maxIdle</name>
<value>5</value>
</parameter>
<!-- Don't use autoReconnect=true, it's going away eventually and it's a
crutch for older connection pools that couldn't test connections.
You need to decide whether your application is supposed to deal with
SQLExceptions (hint, it should), and how much of a performance
penalty you're willing to pay to ensure 'freshness' of the connection -->
<parameter>
<name>validationQuery</name>
<value>SELECT 1</value>
</parameter>
<!-- The most conservative approach is to test connections before they're
given to your application. For most applications this is okay, the
query used above is very small and takes no real server resources to
process, other than the time used to traverse the network. If you have
a high-load application you'll need to rely on something else. -->
<parameter>
<name>testOnBorrow</name>
<value>true</value>
</parameter>
<!-- Otherwise, or in addition to testOnBorrow, you can test while
connections are sitting idle -->
<parameter>
<name>testWhileIdle</name>
<value>true</value>
</parameter>
<!-- You have to set this value, otherwise even though you've asked
connections to be tested while idle,the idle evicter thread
will never run -->
<parameter>
<name>timeBetweenEvictionRunsMillis</name>
<value>10000</value>
</parameter>
<!-- Don't set this too high. A few minutes or even fraction of a minute
is sometimes okay here, it depends on your application and how much
spikey load it will see -->
<parameter>
<name>minEvictableIdleTimeMillis</name>
<value>60000</value>
</parameter>
<!-- Username and password used when connecting to MySQL. Replace myuser
and mypassword with your username/password for the database user. -->
<parameter>
<name>"username"</name>
<value>"password"</value>
</parameter>
<parameter>
<name>"username"</name>
<value>"password"</value>
</parameter>
<!-- Class name for the Connector/J driver -->
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<!-- The JDBC connection url for connecting to MySQL, notice that if
you want to pass any other MySQL-specific parameters you should
pass them here in the URL, setting them using the parameter
tags above will have no effect, you will also need to use &
to separate parameter values as the ampersand is a reserved
character in XML. Replace my_database with your database name. -->
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/gimnasioBackend</value>
</parameter>
</ResourceParams>
</Context>
</webapps>
我将上述配置添加到 Tomcat,但仍然无法连接。我开始对这个问题有点绝望了。
从堆栈跟踪中提取;
Missing type or column for column[descripciono_descripciones] on domain[Ejercicios]
如果列名与驼峰式到下划线格式的约定不匹配,那么通常会从 Hibernate 得到 MappingException
。如果是这种情况,则必须使用 column:
mappings
部分手动完成映射
例如,airportCode column: 'AIRPORT_CD'
修复也会解决部署问题(考虑到没有其他障碍)。
在为这个问题苦苦挣扎了一周之后,在一位同事和 Tomcat 文档的帮助下,我找到了解决方案。
配置在context.xml文件中,如下:
<Resource name="jdbc/turismoBackend" auth="Container" type="javax.sql.DataSource"
maxTotal="100" maxIdle="30" maxWaitMillis="10000"
username="youruser" password="yourpassword" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/yourdb"/>
值得注意的是,为了让 Tomcat 能够访问 MySQL,必须创建一个与 root 不同的用户,并且具有所有权限和授权选项。像这样:
CREATE USER '[yourUsername]'@'localhost' IDENTIFIED BY '[yourPassword]';
GRANT ALL PRIVILEGES TO [yourUsername]@[yourServer] IDENTIFIED BY [yourPassword] WITH GRANT OPTION;
就是这样!一切顺利 运行.