Cloud Foundry v2 in Grails - mysql

I have a grails project and I want to deploy it on Cloud Foundry, but the the console shows this:
[CONTAINER] n.spring.CloudProfileApplicationContextInitializer INFO Adding 'cloud' to list of active profiles
[CONTAINER] g.CloudPropertySourceApplicationContextInitializer INFO Adding 'cloud' PropertySource to ApplicationContext
[CONTAINER] udAutoReconfigurationApplicationContextInitializer INFO Adding cloud service auto-reconfiguration to ApplicationContext
[CONTAINER] ing.DataSourceCloudServiceBeanFactoryPostProcessor INFO Auto-reconfiguring beans of type javax.sql.DataSource
[CONTAINER] ing.DataSourceCloudServiceBeanFactoryPostProcessor INFO No beans of type javax.sql.DataSource found. Skipping auto-reconfiguration.
[CONTAINER] lina.core.ContainerBase.[Catalina].[localhost].[/] SEVERE Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException: Cannot invoke method getAt() on null object
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
Caused by: java.lang.NullPointerException: Cannot invoke method getAt() on null object
at java.lang.Thread.run(Thread.java:745)
[CONTAINER] org.apache.catalina.core.StandardContext SEVERE Error listenerStart
... 5 more
[CONTAINER] org.apache.catalina.util.SessionIdGeneratorBase INFO Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [135] milliseconds.
[CONTAINER] org.apache.catalina.core.StandardContext SEVERE Context [] startup failed due to previous errors
[CONTAINER] org.apache.catalina.loader.WebappClassLoader WARNING The web application [] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
[CONTAINER] org.apache.catalina.loader.WebappClassLoader WARNING The web application [] registered the JDBC driver [org.h2.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
java.lang.Object.wait(Native Method)
[CONTAINER] org.apache.catalina.loader.WebappClassLoader WARNING The web application [] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:142)
I think that it's a problem of DB Conex but I don't know to fix it. I use MySQL in my app and the service plan ClearDB MySQL Database Spark DB.
My Datasource.groovy is:
import org.springframework.cloud.CloudFactory
def cloud
try {
cloud = new CloudFactory().cloud
} catch(e) {}
dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
username = "root"
password = "root"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
//cache.region.factory_class = 'org.hibernate.cache.EhCacheProvider'
}
environments {
development {
dataSource {
dbCreate = "create-drop"
url = "jdbc:mysql://localhost:8080/bbddSRL"
username="root"
password="root"
}
}
test {
dataSource {
dbCreate = "create-drop"
url = "jdbc:mysql://localhost:8080/bbddSRL"
username="root"
password="root"
}
}
production {
dataSource {
pooled = true
dbCreate = 'update'
driverClassName = 'com.mysql.jdbc.Driver'
if (cloud) {
def dbInfo = cloud.getServiceInfo('mysql-instance') //mysql-instance is the name of the ClearDB's service.
url = dbInfo.jdbcUrl
username = dbInfo.userName
password = dbInfo.password
} else {
url = 'jdbc:mysql://localhost:8080/bbddSRLprod'
username = 'root'
password = 'root'
}
}
}
}
Any anwers or suggestions?

Try eliminating the datasource block where you define dialect. You will have to still define the items in that block but do it in the datasource of each environment. I did this because it seemed like any changes that I made to the datasource within the environment had no effect.

Related

ClassNotFoundException when trying to deploy a DataSource with #DataSourceDefinition

I'm trying to deploy a datasource with the #DataSourceDefinition-Annotation.
When wildfly deploys the jar, it throws a ClassNotFoundException.
I put the mysql-jdbc-Driver in the deployment-directory. I already use the com.mysql.jdbc.Driver class in Datasources configured in standalone.xml. I havn't created a module with the jdbc-driver under "modules\system\layers\base"
Here is the Class with the Annotation:
#Stateless
#DataSourceDefinition(name = "java:global/jdbc/testingDS",
className = "com.mysql.jdbc.Driver",
portNumber = 3306,
serverName = "localhost",
databaseName = "testing",
user = "testing",
password = "testing")
public class DataSourceDeployment {
public void someMethod() { }
}
And here is the Exception (this is the *.failed-File):
{
"JBAS014671: Failed services" => {"jboss.deployment.unit.\"DatasourceDeploymentTest-1.jar\".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"DatasourceDeploymentTest-1.jar\".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment \"DatasourceDeploymentTest-1.jar\"
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from [Module \"deployment.DatasourceDeploymentTest-1.jar:main\" from Service Module Loader]
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from [Module \"deployment.DatasourceDeploymentTest-1.jar:main\" from Service Module Loader]"},
"JBAS014771: Services with missing/unavailable dependencies" => [
"jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment.InstanceName is missing [jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment]",
"jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment.ORB is missing [jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment]",
"jboss.deployment.unit.\"DatasourceDeploymentTest-1.jar\".weld.weldClassIntrospector is missing [jboss.deployment.unit.\"DatasourceDeploymentTest-1.jar\".beanmanager]",
"jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment.HandleDelegate is missing [jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment]",
"jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment.ValidatorFactory is missing [jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment]",
"jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment.InAppClientContainer is missing [jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment]",
"jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment.Validator is missing [jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment]"
]
}
CFNE is just as it should be.
You have mysql jdbc driver in module but your deployment and it's #DataSourceDefinition know noting about it.
#DataSourceDefinition uses deployments classloader to load the jdbc driver but it is not available to it as it is in module.
To solve this you should either
1) add deployment's dependency to your mysql driver module via manifest.mf / jboss-deployment-structure.xml, see https://docs.jboss.org/author/display/WFLY8/Class+Loading+in+WildFly for details how
2) add jdbc driver to your war's lib directory
but I would definitely go with 1)

How to start spring-boot app without depending on Database?

I am using "Spring-boot + Hibernate4 + mysql" for my application. As part of which I have a requirement where my sprint-boot app should be able to start even when database is down. Currently it gives the below exception when I try to start my spring boot app without DB being up.
I researched a lot and found out that this exception has to do with hibernate.temp.use_jdbc_metadata_defaults property.
I tried setting this in "application.yml" of spring boot but this property's value is not being reflected at runtime.
Exception Stack Trace:
2014-05-25 04:09:43.193 INFO 59755 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
2014-05-25 04:09:43.250 WARN 59755 --- [ main] o.h.e.jdbc.internal.JdbcServicesImpl : HHH000342: Could not obtain connection to query metadata : Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
2014-05-25 04:09:43.263 INFO 59755 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcat
Error starting ApplicationContext. To display the auto-configuration report enabled debug logging (start with --debug)
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:973)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:750)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:120)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:648)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:311)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:909)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:898)
at admin.Application.main(Application.java:36)
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:104)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:71)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:205)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:399)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:150)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:336)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
... 15 more
application.yml:
spring:
jpa:
show-sql: true
hibernate:
ddl-auto: none
naming_strategy: org.hibernate.cfg.DefaultNamingStrategy
temp:
use_jdbc_metadata_defaults: false
It was indeed a tough nut to crack.
After lot and lot of research and actually debugging the spring-boot, spring, hibernate, tomcat pool, etc to get it done.
I do think that it will save lot of time for people trying to achieve this type of requirement.
Below are the settings required to achieve the following requirement
Spring boot apps will start fine even if DB is down or there is no DB.
Apps will pick up the connections on the fly as DB comes up which means there is no need to restart the web server or redeploy the apps.
There is no need to start the tomcat or redeploy the apps, if DB goes down from running state and comes up again.
application.yml :
spring:
datasource:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/schema
username: root
password: root
continueOnError: true
initialize: false
initialSize: 0
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 5000
minIdle: 0
jpa:
show-sql: true
hibernate:
ddl-auto: none
naming_strategy: org.hibernate.cfg.DefaultNamingStrategy
properties:
hibernate:
dialect: org.hibernate.dialect.MySQL5Dialect
hbm2ddl:
auto: none
temp:
use_jdbc_metadata_defaults: false
I am answering here and will close the issue that you have cross-posted
Any "native" property of the JPA implementation (Hibernate) can be set using the spring.jpa.properties prefix as explained here
I haven't looked much further in the actual issue here but to answer this particular question, you can set that hibernate key as follows
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults
Adding this alone worked for me:
spring.jpa.properties.hibernate.dialect: org.hibernate.dialect.Oracle10gDialect
Just replace the last part with your database dialect.
The solution is really useful for me. Thanks
i used file "application.properties" includes following lines:
app.sqlhost=192.168.10.11
app.sqlport=3306
app.sqldatabase=logs
spring.main.web-application-type=none
# Datasource
spring.datasource.url=jdbc:mysql://${app.sqlhost}:${app.sqlport}/${app.sqldatabase}
spring.datasource.username=user
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.hbm2dll.auto = none
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
spring.datasource.continue-on-error=true
spring.datasource.initialization-mode=never
spring.datasource.hikari.connection-timeout=5000
spring.datasource.hikari.idle-timeout=600000
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.initialization-fail-timeout= -1
spring.jpa.hibernate.use-new-id-generator-mappings=true
spring.jpa.hibernate.ddl-auto=none
spring.jpa.show-sql=true
spring.output.ansi.enabled=always
But, you can not use #Transactional annotation at class level
#Service
//#Transactional //do not use to touch the Repository
#EnableAsync
#Scope( proxyMode = ScopedProxyMode.TARGET_CLASS )
public class LogService {
.... }
#Async
#Transactional // you can use at function level
public void deleteLogs(){
logRepository.deleteAllBy ...
}
Add following config should be work:
spring.jpa.database-platform: org.hibernate.dialect.MySQL5Dialect

Why do I get an H2 error when deploying my Grails WAR to Tomcat

I'm trying to deploy my Grails 2.2.4 application to Tomcat 6.5. The application has two environments configured in DataSource.groovy.
Whether I build my application using 'mvn clean package' or thru the 'grails war' I get an error about a particular table not existing. When I launch the application thru 'groovy run-app' I have no problems connection to the same database. Any idea of what's wrong with my config?
Tomcat Deployment Error
Nov 12, 2013 4:16:38 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener
org.springframework.beans.factory.access.BootstrapException: Error executing bootstraps; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; SQL [select count(*) as y0_ from monkey_classification this_]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
at org.codehaus.groovy.grails.web.context.GrailsContextLoader.initWebApplicationContext(GrailsContextLoader.java:124)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1655)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:636)
Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; SQL [select count(*) as y0_ from monkey_classification this_]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
at BootStrap$_closure4.doCall(BootStrap.groovy:24)
at grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java:308)
at grails.util.Environment.executeForEnvironment(Environment.java:301)
at grails.util.Environment.executeForCurrentEnvironment(Environment.java:277)
... 6 more
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
... 10 more
Caused by: org.h2.jdbc.JdbcSQLException: Table "MONKEY_CLASSIFICATION" not found; SQL statement:
select count(*) as y0_ from monkey_classification this_ [42102-164]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
at org.h2.message.DbException.get(DbException.java:169)
at org.h2.message.DbException.get(DbException.java:146)
at org.h2.command.Parser.readTableOrView(Parser.java:4753)
at org.h2.command.Parser.readTableFilter(Parser.java:1080)
at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1686)
at org.h2.command.Parser.parseSelectSimple(Parser.java:1793)
at org.h2.command.Parser.parseSelectSub(Parser.java:1680)
at org.h2.command.Parser.parseSelectUnion(Parser.java:1523)
at org.h2.command.Parser.parseSelect(Parser.java:1511)
at org.h2.command.Parser.parsePrepared(Parser.java:405)
at org.h2.command.Parser.parse(Parser.java:279)
at org.h2.command.Parser.parse(Parser.java:251)
at org.h2.command.Parser.prepareCommand(Parser.java:217)
at org.h2.engine.Session.prepareLocal(Session.java:415)
at org.h2.engine.Session.prepareCommand(Session.java:364)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1121)
at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:71)
at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:267)
at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:281)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:313)
... 10 more
Nov 12, 2013 4:16:38 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Nov 12, 2013 4:16:38 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/application-monkey-tool-0.1] startup failed due to previous errors
Nov 12, 2013 4:16:38 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
Nov 12, 2013 4:16:38 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/application-monkey-tool-0.1] registered the JDBC driver [org.h2.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Nov 12, 2013 4:16:38 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/application-monkey-tool-0.1] appears to have started a thread named [net.sf.ehcache.CacheManager#1b4a4fd2] but has failed to stop it. This is very likely to create a memory leak.
DataSource.groovy:
dataSource {
pooled = true
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
driverClassName = "com.mysql.jdbc.Driver"
username = "amt"
password = "password"
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:mysql://10.x.x.x:3306/amt"
}
}
test {
dataSource {
driverClassName = "org.h2.Driver"
username = "sa"
password = ""
dbCreate = "update"
url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
}
}
production {
dataSource {
dataSource {
driverClassName = "com.mysql.jdbc.Driver"
username = "amt"
password = "password"
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:mysql://10.x.x.x:3306/amt"
}
}
}
}
maven build output
[INFO] --- grails-maven-plugin:2.2.4:maven-grails-app-war (default-maven-grails-app-war) # application-monkey-tool ---
|Loading Grails 2.2.4
|Configuring classpath
|Running pre-compiled script
.
|Environment set to prod
.................................
|Packaging Grails application
..
|Compiling 1 source files
..............
|Compiling 21 GSP files for package [applicationMonkeytOol]
..
|Compiling 8 GSP files for package [jodaTime]
.
|Compiling 7 GSP files for package [easygrid]
.
|Compiling 4 GSP files for package [databaseMigration]
..
|Building WAR file
..............................................................
|Done creating WAR target\application-monkey-tool-0.1.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 52.528s
[INFO] Finished at: Tue Nov 12 11:12:57 EST 2013
[INFO] Final Memory: 10M/244M
[INFO] ------------------------------------------------------------------------
Looks like you have two dataSource defined in your dsl, should be like this:
production {
dataSource {
driverClassName = "com.mysql.jdbc.Driver"
username = "amt"
password = "password"
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:mysql://10.x.x.x:3306/amt"
}
}

ESB Mule Client staring with xml-properties fails

I use Mule 3.x
I have a code that tests MuleClient connectivity.
This test is ok and works proper way:
public void testHello() throws Exception
{
MuleClient client = new MuleClient(muleContext);
MuleMessage result = client.send("http://127.0.0.1:8080/hello", "some data", null);
assertNotNull(result);
assertNull(result.getExceptionPayload());
assertFalse(result.getPayload() instanceof NullPayload);
//TODO Assert the correct data has been received
assertEquals("hello", result.getPayloadAsString());
}
But this tes is not ok - it fail with an connection exceptions:
public void testHello_with_Spring() throws Exception {
MuleClient client = new MuleClient("mule-config-test.xml");
client.getMuleContext().start();
//it fails here
MuleMessage result = client.send("http://127.0.0.1:8080/hello", "some data", null);
assertNotNull(result);
assertNull(result.getExceptionPayload());
assertFalse(result.getPayload() instanceof NullPayload);
//TODO Assert the correct data has been received
assertEquals("hello", result.getPayloadAsString());
}
The 'mule-config-test.xml' is used in both tests, the path for this file is ok, i checked.
This is error message I have in the end:
Exception stack is:
1. Address already in use (java.net.BindException) java.net.PlainSocketImpl:-2 (null)
2. Failed to bind to uri "http://127.0.0.1:8080/hello" (org.mule.transport.ConnectException)
org.mule.transport.tcp.TcpMessageReceiver:81
(http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/transport/ConnectException.html)
-------------------------------------------------------------------------------- Root Exception stack trace: java.net.BindException: Address already in
use at java.net.PlainSocketImpl.socketBind(Native Method) at
java.net.PlainSocketImpl.bind(PlainSocketImpl.java:383) at
java.net.ServerSocket.bind(ServerSocket.java:328)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
[10-05 16:33:37] ERROR HttpConnector [main]:
org.mule.transport.ConnectException: Failed to bind to uri
"http://127.0.0.1:8080/hello" [10-05 16:33:37] ERROR ConnectNotifier
[main]: Failed to connect/reconnect: HttpConnector {
name=connector.http.mule.default lifecycle=stop this=7578a7d9
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true connected=false
supportedProtocols=[http] serviceOverrides= } . Root Exception
was: Address already in use. Type: class java.net.BindException [10-05
16:33:37] ERROR DefaultSystemExceptionStrategy [main]: Failed to bind
to uri "http://127.0.0.1:8080/hello"
org.mule.api.lifecycle.LifecycleException: Cannot process event as
"connector.http.mule.default" is stopped
I think the problem is in what you're not showing: testHello_with_Spring() is probably executing while Mule is already running. The second Mule you're starting in it then port-conflicts with the other one.
Are testHello() and testHello_with_Spring() in the same test suite? If yes, seeing that testHello() relies on an already running Mule, I'd say that would be the cause of port conflict for testHello_with_Spring().

Grails war deployment on Tomcat asking for hsql driver instead of mysql

I have a grails app that I am trying to deploy onto Tomcat. I used to develop on hsql and wanted to use mysql for production. But when I build the war by running
grails prod war demo.war
and deploy the created war in the tomcat/webapps directory, I get the following error
INFO: Deploying web application archive demo.war
2011-11-29 17:30:03,193 [Thread-2] INFO cfg.Environment - Hibernate 3.3.1.GA
2011-11-29 17:30:03,224 [Thread-2] INFO cfg.Environment - hibernate.properties not found
2011-11-29 17:30:03,240 [Thread-2] INFO cfg.Environment - Bytecode provider name : javassist
2011-11-29 17:30:03,251 [Thread-2] INFO cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
2011-11-29 17:31:25,451 [Thread-2] ERROR context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'org.hsqldb.jdbcDriver' for connect URL 'jdbc:mysql://localhost:3306/demoapp?autoreconnect=true'
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
What's puzzling is that I have removed the hsql dependency completely from the Datasource.groovy file. Here is how my Datasource.groovy looks now.
dataSource {
pooled = true
driver.name = "com.mysql.jdbc.Driver"
username = "root"
password = "root"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop','update'
pooled = true
driver.name = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://localhost/demoapp_dev?autoreconnect=true"
username = "root"
password = ""
}
}
test {
dataSource {
pooled = true
driver.name = "com.mysql.jdbc.Driver"
dbCreate = "update"
url = "jdbc:mysql://localhost/demoapp_test?autoreconnect=true"
username = "root"
password = ""
}
}
production {
dataSource {
pooled = true
driver.name = "com.mysql.jdbc.Driver"
dbCreate = "update"
url = "jdbc:mysql://localhost/demoapp?autoreconnect=true"
username = "root"
password = ""
}
}
}
How do I get around this problem? Any help is appreciated.
Try using driverClassName instead of driver.name to define your DataSource driver.
This happens when you don't have the MySQL driver in your class path don't have the driverClassName, as per schmolly159's answer.
Make sure mysql-connector-java-x.x.xx.jar is in your lib directory or declare it as a dependency in BuildConfig.groovy.