Skip to content

RedisService withConnection broken due to unwired grailsApplication #72

Closed

Description

@yuenhsi

Currently, calling redisService.withConnection throws a NullPointerException.

RedisService withConnection(String connectionName){
        if(grailsApplication.mainContext.containsBean("redisService${connectionName.capitalize()}")){
            return (RedisService)grailsApplication.mainContext.getBean("redisService${connectionName.capitalize()}")
        }
        ...
    }

Referencing grailsApplication.mainContext causes the exception, with the message being Cannot get property 'mainContext' on null object. I believe autowiring GrailsApplication is not done properly, seeing that this is the only method that makes use of this bean. I look a look at the tests, and it seems like even though retrieving the GrailsApplication bean is tested in a vacuum, the withConnection method itself is not touched.

Currently a workaround for this issue is adding the following to BootStrap.groovy.

def grailsApplication
    def redisService

    def init = { servletContext ->
        redisService.grailsApplication = grailsApplication
    }

Activity

  1. ctoestreich commented on Dec 9, 2016

    @ctoestreich
    Contributor

    What version of grails/plugin?

  2. yuenhsi commented on Dec 11, 2016

    @yuenhsi
    Author

    This happens on Grails 3.1.12, using what I believe the only version of Redis plugin (v2.0.4) available for Grails 3.x.x.

    https://bintray.com/ctoestreich/grails-plugins/redis

  3. Joshua-Brent-Collins commented on Aug 2, 2017

    @Joshua-Brent-Collins

    I also see this using Redis-Plugin 2.0.4, Grails 3.2.11, Groovy 2.4.11 and JVM 1.8.0_31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions