grails plugin has conflicting cachemanager name - grails

I'm trying to develop a grails 2.4.X plugin to add domain objects. When I run my application I get this in the application including the plugin:
Caused by CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.
The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ]
->> 628 | assertNoCacheManagerExistsWithSameName in net.sf.ehcache.CacheManager
I assume that DataSource and Config (in the plugin) are over-written.
I updated the plugin to use to use BeanEhcacheRegionFactory4:
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
// cache.region.factory_class = 'net.sf.ehcache.hibernate.BeanEhcacheRegionFactory' // Hibernate 3
cache.region.factory_class = 'org.hibernate.cache.ehcache.BeanEhcacheRegionFactory4' // Hibernate 4
singleSession = true // configure OSIV singleSession mode
flush.mode = 'manual' // OSIV session flush mode outside of transactional context
}
Grails ehcache plugin - Another unnamed CacheManager already exists in the same VM
I don't have an ehcache.xml so I'm assuming it is using the groovy configuration.
Is this something that would be fixed by moving to 2.5 / 3?
Removing the ehcache plugin "fixes" this problem.

Related

java.lang.IllegalStateException: No Datastore Session bound to thread, and configuration does not allow creation of non-transactional one here

am getting the below error when i run grails app in my local
file:/home/schepuri/grails/2.4.4/projects/my-app/plugins/excel-import-0.9.6/lib/xmlbeans-2.3.0-without-w3c.jar
-------------------------------------------------------------
java.lang.IllegalStateException: No Datastore Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.grails.datastore.mapping.core.DatastoreUtils.doGetSession(DatastoreUtils.java:149)
at org.grails.datastore.mapping.core.AbstractDatastore.getCurrentSession(AbstractDatastore.java:141)
at org.grails.datastore.gorm.GormStaticApi.createCriteria(GormStaticApi.groovy:297)
Here is my BuildConfig.groovy file
dependencies {
compile 'org.grails:grails-datastore-gorm-plugin-support:3.1.3.RELEASE'
compile 'org.grails:grails-datastore-gorm:3.1.3.RELEASE'
compile 'org.grails:grails-datastore-core:3.1.3.RELEASE'
}
plugins {
compile (":mongodb:3.0.2") {
excludes 'grails-datastore-gorm-plugin-support'
excludes 'grails-datastore-gorm'
excludes 'grails-datastore-core'
}
}
Am i missing any dependency plugins in my buildconfig file or

Excluding a Grails build scope dependency

Using Grails 2.4.3, how can I exclude a dependency that's defined in the build scope?
ExampleGrails is bundled with the library spock-core-0.7-groovy-2.0.jar; when adding the standard global dependency exclusion:
...
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits('global') {
excludes 'spock-core'
}
...
Spock is excluded from all dependency scopes except for the build scope.
Is the issue that you don't want it in your .war file? If so you can remove it like so:
grails.war.resources = { stagingDir ->
delete(file:"${stagingDir}/WEB-INF/lib/spock-core-0.7-groovy-2.0.jar")
}

Grails Logging not working in Forked Mode

I'm having a problem where logging works correctly when I run tomcat in non-forked mode from grails, but does not work correctly in forked mode.
Here is my Log4j configuration:
Config.groovy:
// log4j configuration
log4j = {
appenders {
file name:"fileLogger", file: "c:/logs/app-log.log", threshold: Level.DEBUG
}
debug fileLogger: ['com.foo', 'BootStrap']
info fileLogger: ['org.springframework']
error fileLogger: [
'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.hibernate',
'net.sf.ehcache.hibernate']
}
When I run grails run-app, the log file is correcly populated.
However, when I change my BuildConfig.groovy file to run tomcat in forked mode:
BuildConfig.groovy:
grails.project.fork = [
run: [maxMemory:1024, minMemory:64, debug:false, maxPerm:256]
]
The log file does not get populated.
Is there something wrong with my configuration? Why would it work in one mode, but not the other?
You have the threshold for the appender set to DEBUG level. I think in the forked tomcat mode the default level is set to INFO. In order to make it work for the forked mode you might need to increase the logging level to INFO and change DEBUGs to INFOs.
info fileLogger: ['org.springframework', 'com.foo', 'BootStrap']

Error running grails run-war after half a day

I have a 2.1.1 grails app which I am running using grails run-war. It works well, and runs for quite some time, but stops after something between 12 and 24 hours. I am never observing the app when it fails. It always just says "bad"
$ grails run-war
| Done creating WAR target/web-0.1.war
| Running Grails application
Tomcat Server running WAR (output written to: target/tomcat-out.txt)
| Server running. Browse to http://localhost:8090/web
bad
$
2 of the last 3 failures has produced this in the output file:
2012-10-10 10:22:46,684 [localhost-startStop-2] ERROR loader.WebappClassLoader - The web application [/web] appears to have started a thread named [Poller SunPKCS11-Darwin] but has failed to stop it. This is very likely to create a memory leak.
2012-10-10 10:22:46,694 [localhost-startStop-2] ERROR loader.WebappClassLoader - The web application [/web] appears to have started a thread named [MongoCleaner1292971653] but has failed to stop it. This is very likely to create a memory leak.
However most of the time, there is nothing in the log file.
This happens even if nobody has used the webapp, ie its been idle. The plugins in use are:
runtime ":mongodb:1.0.0.GA"
runtime ":jquery:1.7.2"
compile ":jquery-ui:1.8.15"
runtime ":resources:1.2-RC1"
// Uncomment these (or add new ones) to enable additional resources capabilities
//runtime ":zipped-resources:1.0"
//runtime ":cached-resources:1.0"
//runtime ":yui-minify-resources:0.1.4"
build ":tomcat:$grailsVersion"
WHen using grails 2.0.4, this same app ran for weeks without failing. The only change is the upgrade to grails 2.1.1
Any thoughts?
Thanks
Edit:
Including the DataSource.groovy
dataSource {
pooled = true
driverClassName = "org.h2.Driver"
username = "sa"
password = ""
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:h2:mem:devDb;MVCC=TRUE"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:h2:mem:testDb;MVCC=TRUE"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:h2:prodDb;MVCC=TRUE"
pooled = true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
}
}
Then in each Model,
class Album {
static mapWith = "mongo"
I do this to ensure I use Mongo as each time I upgrade grails, it automatically re-installs the hibernate plugin even though I keep uninstalling it.
Thanks

Grails 2.0 plugin dependencies

I'm trying to build a Grails 2.0 application using private plugins:
mycompany-frontend = Grails Application
mycompany-core = Grails plugins for domain classes
In the mycompany-core plugin, I created some domain classe and added a joda-time dependency in BuildConfig.groovy:
plugins {
build(":tomcat:$grailsVersion",
":release:1.0.1",
":svn:1.0.2") {
export = false
}
build(":joda-time:1.3.1")
}
in the mycompany-frontend app, I have the following BuildConfig.groovy:
plugins {
runtime ":hibernate:$grailsVersion"
runtime ":resources:1.1.5"
build "mycompany:mycompany-core:0.1-SNAPSHOT"
build ":svn:1.0.2"
build ":spring-security-core:1.2.7"
build ":tomcat:$grailsVersion"
}
I also removed grails.plugins entries from application.properties to avoid confusion.
But at the end, the mycompany-frontend cannot find the model classes from mycompany-core plugin.
What should I look/fix to get this working?
Have you tried to define the dependency to your core-plugin as runtime-/compile-dependency instead of build?

Resources