I get this error below when running a Grails 2.4.5 project (full stacktrace)
Error |
2021-11-28 01:27:44,302 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener - Error initializing the application: Error creating bean with name 'ehCacheManagementService': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: net.sf.ehcache.CacheException: javax.management.MalformedObjectNameException: Invalid character ':' in value part of property
Message: Error creating bean with name 'ehCacheManagementService': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: net.sf.ehcache.CacheException: javax.management.MalformedObjectNameException: Invalid character ':' in value part of property
Line | Method
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1149 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 624 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 748 | run in java.lang.Thread
Caused by CacheException: net.sf.ehcache.CacheException: javax.management.MalformedObjectNameException: Invalid character ':' in value part of property
->> 246 | init in net.sf.ehcache.management.ManagementService
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 266 | run in java.util.concurrent.FutureTask
| 1149 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 624 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 748 | run . . . in java.lang.Thread
Caused by CacheException: javax.management.MalformedObjectNameException: Invalid character ':' in value part of property
->> 76 | createObjectName in net.sf.ehcache.management.Cache
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 64 | <init> in ''
| 107 | getCache in net.sf.ehcache.management.CacheManager
| 126 | getCaches in ''
| 237 | init . . in net.sf.ehcache.management.ManagementService
| 266 | run in java.util.concurrent.FutureTask
| 1149 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 624 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 748 | run . . . in java.lang.Thread
Caused by MalformedObjectNameException: Invalid character ':' in value part of property
->> 618 | construct in javax.management.ObjectName
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1382 | <init> in ''
| 73 | createObjectName in net.sf.ehcache.management.Cache
| 64 | <init> in ''
| 107 | getCache in net.sf.ehcache.management.CacheManager
| 126 | getCaches in ''
| 237 | init . . in net.sf.ehcache.management.ManagementService
| 266 | run in java.util.concurrent.FutureTask
| 1149 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 624 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 748 | run . . . in java.lang.Thread
Error |
2021-11-28 01:27:44,339 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener - Error initializing Grails: Error creating bean with name 'ehCacheManagementService': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: net.sf.ehcache.CacheException: javax.management.MalformedObjectNameException: Invalid character ':' in value part of property
Message: Error creating bean with name 'ehCacheManagementService': Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: net.sf.ehcache.CacheException: javax.management.MalformedObjectNameException: Invalid character ':' in value part of property
Line | Method
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1149 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 624 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 748 | run in java.lang.Thread
Caused by CacheException: net.sf.ehcache.CacheException: javax.management.MalformedObjectNameException: Invalid character ':' in value part of property
->> 246 | init in net.sf.ehcache.management.ManagementService
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 266 | run in java.util.concurrent.FutureTask
| 1149 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 624 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 748 | run . . . in java.lang.Thread
Caused by CacheException: javax.management.MalformedObjectNameException: Invalid character ':' in value part of property
->> 76 | createObjectName in net.sf.ehcache.management.Cache
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 64 | <init> in ''
| 107 | getCache in net.sf.ehcache.management.CacheManager
| 126 | getCaches in ''
| 237 | init . . in net.sf.ehcache.management.ManagementService
| 266 | run in java.util.concurrent.FutureTask
| 1149 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 624 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 748 | run . . . in java.lang.Thread
Caused by MalformedObjectNameException: Invalid character ':' in value part of property
->> 618 | construct in javax.management.ObjectName
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1382 | <init> in ''
| 73 | createObjectName in net.sf.ehcache.management.Cache
| 64 | <init> in ''
| 107 | getCache in net.sf.ehcache.management.CacheManager
| 126 | getCaches in ''
| 237 | init . . in net.sf.ehcache.management.ManagementService
| 266 | run in java.util.concurrent.FutureTask
| 1149 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 624 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 748 | run . . . in java.lang.Thread
Error |
2021-11-28 01:27:44,345 [localhost-startStop-1] ERROR core.StandardContext - Error listenerStart
Error |
2021-11-28 01:27:44,347 [localhost-startStop-1] ERROR core.StandardContext - Context [/soctrack-web] startup failed due to previous errors
|Server running. Browse to http://localhost:8080/soctrack-web
I am not sure what's causing the error, I get a successful "maven clean/package/install". However, doing a "grails compile", I get a deprecated warning (as show below) from the cache-ehcache plugin, I am assuming that might be the reason why I am getting this error, but not sure how to solve it.
Note: C:\Users\kgeoffroy\Documents\dev\soc-track-upgrade\SOCScheduleServiceWEB\target\plugins\cache-ehcache-1.0.5\src\java\grails\plugin\cache\ehcache\G
railsEhCacheManagerFactoryBean.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
I will try to see if there are higher version of that plugin. So far I am constricted to a nexus mirror repository for the most part, so I haven't been able to find a higher version to test.
I have the sample dependencies inside my pom.xml
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>cache-ehcache</artifactId>
<version>1.0.5</version>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>hibernate4</artifactId>
<version>4.3.8.1</version>
<scope>runtime</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>tomcat</artifactId>
<version>7.0.55.2</version>
<scope>provided</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>cache</artifactId>
<version>1.1.8</version>
<scope>compile</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>cache-headers</artifactId>
<version>1.1.7</version>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>cached-resources</artifactId>
<version>1.1</version>
<type>zip</type>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.8.1</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
According to an open issue https://github.com/grails-plugins/grails-cache-ehcache/issues/41, it might be a possible bug, but no solution or work around was provided.
I am doing an upgrade from Grails 2.2.0 to 2.4.5, I have updated the Datasource.groovy to point out to the right hibernate4 ehCache class:
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
// cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider' //Outdated class
// http://grails-plugins.github.io/grails-cache-ehcache/guide/usage.html
cache.region.factory_class = 'grails.plugin.cache.ehcache.hibernate.BeanEhcacheRegionFactory' // For Hibernate before 4.0
cache.region.factory_class = 'grails.plugin.cache.ehcache.hibernate.BeanEhcacheRegionFactory4' // For Hibernate before 4.0 and higher
}
config.groovy:
/*https://github.com/grails/grails-core/releases/tag/v2.4.5
* ehcache 2.9.0 is more strict about the configuration.
* ehcache is used in the spring-security-core plugin for caching users.
* There is a problem reported as GRAILS-12120.
* As a workaround to the "net.sf.ehcache.CacheException:
* Another unnamed CacheManager already exists in the same VM.
* " error you can add this config to Config.groovy:*/
beans {
cacheManager {
shared = true
}
}
I am trying to understand where that MalformedObjectNameException: Invalid character ':' in value part of property
is coming from since the project didn't configure any ehcache, it just used some classes from the cache plugin. Here is a sample cache service implementation below:
GrailsEhCacheCache not recognized by IntelliJ GrailsCacheManager not recognized by IntelliJ
import grails.plugin.cache.GrailsCacheManager
import grails.plugin.cache.ehcache.GrailsEhcacheCache
import org.springframework.transaction.annotation.Transactional
class ChatCacheService
{
static transactional = false
static final String CHAT_CACHE_NAME = Chat.canonicalName
static final String CHAT_HASHES_CACHE_NAME = "${CHAT_CACHE_NAME}.Hashes"
GrailsCacheManager grailsCacheManager
ChatMessageCacheService chatMessageCacheService
FilterService filterService
GrailsEhcacheCache getChatCache()
{
grailsCacheManager.getCache(CHAT_CACHE_NAME) as GrailsEhcacheCache
}
GrailsEhcacheCache getChatHashesCache()
{
grailsCacheManager.getCache(CHAT_HASHES_CACHE_NAME) as GrailsEhcacheCache
}
void addNewChat(String chatChannelName, Chat chat)
{
chatMessageCacheService.createChatMessageCache(chatChannelName, chatCache)
chat.channelName = chatChannelName
refreshChat(chatCache, chat)
}
void refreshChat(Chat chat)
{
refreshChat(chatCache, chat)
}
void refreshChat(GrailsEhcacheCache chatCache, Chat chat)
{
chat.updateChatTimestamp()
chatCache.put(chat.channelName, chat)
// >>> Chat Cache Event listener will update hash, except during initialization
}
void refreshChatHash(Chat chat)
{
ChatHash chatHash = chat.generateHashCode(chatMessageCacheService.getCacheChatMessages(chat.channelName))
chatHashesCache.put(chat.channelName, chatHash)
}
Chat retrieveChat(String chatChannelName)
{
Chat chat = chatCache.get(chatChannelName)?.get() as Chat
chat
}
synchronized Chat retrieveNonPurgeableChat(String chatChannelName)
{
Chat chat = retrieveChat(chatChannelName)
if (!chat)
{
addNewChat(chatChannelName, new NonPurgeableChat())
chat = retrieveChat(chatChannelName)
}
chat
}
List<ChatChatMessage> getCacheChatMessages(String channelName)
{
chatMessageCacheService.getCacheChatMessages(channelName) //.sort { -it.id }
}
ChatChatMessage addNewChatMessageCache(String channelName, ChatMessage chatMessage)
{
Chat chat = retrieveChat(channelName)
chatMessageCacheService.addNewChatMessageCacheToTop(channelName, chatMessage)
refreshChat(chat) // refresh chat
}
void removeChat(String chatChannelName)
{
GrailsEhcacheCache chatCache = grailsCacheManager.getCache(CHAT_CACHE_NAME) as GrailsEhcacheCache
chatCache.evict(chatChannelName)
chatMessageCacheService.destroy(chatChannelName)
}
@Transactional(readOnly = true)
List<Chat> retrieveAllGeneralAndGroupChats()
{
List<Chat> generalAndGroupChats = []
List<ChatMessageType> generalAndGroupChatTypes = [
ChatMessageType.findByDescription(ChatType.GROUP.name()),
ChatMessageType.findByDescription(ChatType.GENERAL.name())
]
chatCache.allKeys.each { key ->
Chat chat = (Chat) chatCache.get(key).get()
if (generalAndGroupChatTypes.find { it?.description == chat?.chatTypeDescription })
{
generalAndGroupChats.add(chat)
}
}
generalAndGroupChats
}
void purgeOldMessagesFromChats()
{
chatCache.allKeys.findAll { String channelName -> !ChatService.isEventChat(channelName) }.each { String chatChannelName ->
Chat chat = (Chat) chatCache.get(chatChannelName).get()
if (!(chat instanceof NonPurgeableChat))
{
if (chatMessageCacheService.purgeOldMessages(chatChannelName) > 0)
{
refreshChat(chatCache, chat)
}
}
}
}
String getChatCacheHash(String channelName)
{
((ChatHash) chatHashesCache.get(channelName)?.get())?.hash
}
String synchronizeChat(UserProfile userProfile, String chatChannelName, String chatTimestamp, String selectedFilter)
{
String response = null
Chat chatToSynchronize = retrieveChat(chatChannelName)
if (chatToSynchronize && (chatTimestamp != getChatCacheHash(chatToSynchronize.channelName) || filterChanged(userProfile, selectedFilter)))
{
response = chatToJson(chatToSynchronize, filterService.getCurrentFilterForUsername(userProfile?.userId), selectedFilter, userProfile)
}
response
}
Boolean filterChanged(UserProfile userProfile, String selectedFilter) {
Boolean filterChanged = Boolean.FALSE
if (userProfile && userProfile?.groupChatFilterOption != selectedFilter
&& (userProfile?.groupChatFilterOption == SOCTrackConstants.DASHBOARD_FILTER || selectedFilter == SOCTrackConstants.DASHBOARD_FILTER)) {
filterChanged = Boolean.TRUE
}
filterChanged
}
String chatToJson(Chat chat, List<EventFilter> userFilters, String selectedFilter, UserProfile userProfile)
{
List<ChatChatMessage> chatChatMessages = chatMessageCacheService.getCacheChatMessages(chat.channelName)
// Apply dashboard filters
if (selectedFilter == SOCTrackConstants.DASHBOARD_FILTER) {
chatChatMessages = chatChatMessages.findAll{ChatChatMessage chatMessage ->
includeChatMessage(chatMessage, userFilters)
}
}
Map<String, Collection<String>> chatMessagesAndTimestamp = [:]
chatMessagesAndTimestamp['messages'] = chatChatMessages.collect { ChatChatMessage chatMessage ->
chatMessage.messageAsHtml = chatMessage.messageAsHtmlClone
if (! userProfile?.shouldHighlightGroupMessage(chatMessage.id, chatMessage.enteredDate, chatMessage.messageType) ||
chatMessage.enteredBy.equals(userProfile?.userId)) {
chatMessage.messageAsHtml = chatMessage.messageAsHtml.replaceAll("groupChatUnreadHighlight","")
}
if(chatMessage.lastResponseId > 0) {
if (!userProfile?.shouldHighlightGroupMessage(chatMessage.lastResponseId, chatMessage.lastResponseDate, chatMessage.messageType) ||
chatMessage.lastResponseBy.equals(userProfile?.userId)) {
chatMessage.messageAsHtml = chatMessage.messageAsHtml.replaceAll("groupChatResponseUnreadHighlight", "")
}
}
chatMessage.messageAsHtml
}.findAll { it }
chatMessagesAndTimestamp['chatTimestamp'] = getChatCacheHash(chat.channelName) // chat.chatTimestamp
JSON messagesAsJson = new JSON(chatMessagesAndTimestamp)
messagesAsJson.toString()
}
Boolean includeChatMessage (ChatChatMessage chatChatMessage, List<EventFilter> userFilters) {
boolean displayRow = true
if (userFilters) { //at least one filter to satisfy
boolean satisfiedAllAndFilters
boolean satisfiedAnOrFilter
List<EventFilter> andFilters = userFilters.findAll { eventFilter ->
eventFilter.filterOperationType == FilterOperationType.AND
}
List<EventFilter> orFilters = userFilters.findAll { eventFilter ->
eventFilter.filterOperationType == FilterOperationType.OR
}
if (andFilters) {
satisfiedAllAndFilters = andFilters.collect { andFilter ->
andFilter.displayChatBasedOnFilter(chatChatMessage)
}.every{ it } //all 'AND' filters must be satisfied
}
if (orFilters) {
satisfiedAnOrFilter = orFilters.collect { orFilter ->
orFilter.displayChatBasedOnFilter(chatChatMessage)
}.any{ it } //at least one 'OR' filter must be satisfied
}
displayRow = satisfiedAllAndFilters || satisfiedAnOrFilter
}
displayRow
}
}
UPDATE: Custom Utility method used to createEHcache
synchronized static Cache createEhcache(String name, CacheManager cacheManager, CacheConfiguration baseCacheConfiguration, CacheEventListener cacheEventListener = null)
{
Ehcache ehcache
PersistenceConfiguration persistenceConfiguration
if (cacheManager.cacheExists(name))
{
ehcache = cacheManager.getCache(name)
ehcache.cacheConfiguration.overflowToDisk = false //overflowToDisk deprecated
// ehcache.cacheConfiguration.persistence(persistenceConfiguration.strategy("LOCALTEMPSWAP"))
ehcache.cacheConfiguration.diskPersistent = false // diskPersistent deprecated
// ehcache.cacheConfiguration.persistence(persistenceConfiguration.strategy("NONE"))
ehcache.cacheConfiguration.timeToLiveSeconds = 0
ehcache.cacheConfiguration.timeToIdleSeconds = 0
logger.warn "Cache $name already exists, configuration has been reset."
}
else
{
baseCacheConfiguration.name = name
// ehcache = new Cache(baseCacheConfiguration, null, null); //Runtime error (Ambiguous method overloading)
// RegisteredEventListeners registeredEventListeners = new RegisteredEventListeners(null);
// BootstrapCacheLoader bootstrapCacheLoader = new RMIBootstrapCacheLoader()
ehcache = new Cache(baseCacheConfiguration, null as RegisteredEventListeners, null as BootstrapCacheLoader)
cacheManager.addCache(ehcache)
cacheManager.cacheManagerPeerProviders?.get('RMI')?.registerPeer("${getEhcachePeerBaseUrl()}/$baseCacheConfiguration.name")
if (cacheEventListener)
{
ehcache.getCacheEventNotificationService().registerListener(cacheEventListener)
}
}
ehcache
}
CodePudding user response:
Putting that line of code inside the Config.groovy file solved the issue and removed the exception: grails.cache.ehcache.cacheManagerName = 'default_grails_cache'
.
Solution comes from https://github.com/grails-plugins/grails-cache-ehcache/issues/41#issuecomment-985049476.