Grails

ConfigurationHolder.config null inside DataSource.groovy for WAR builds

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.1.1
  • Fix Version/s: 1.2-M1
  • Component/s: Configuration
  • Labels:
    None

Description

Using a 1.1.1 project, if you reference application configuration using the ConfigurationHolder.config object in a WAR deployment, you will get a NullPointerException. The ConfigurationHolder.config object appears to be null in WAR deployments. This occurs both if you create a WAR and deploy it to a servlet container, or if you execute the run-war command from your project root.

Issue Links

Activity

Hide
Graeme Rocher added a comment -

I've written an application that does:

def read = {
		def one = grailsApplication.config.test.value1
		def two = ConfigurationHolder.config.test.value2
		
		render "one = $one, two = $two"
	}

And it works fine in both WAR and run-app. I have however committed a functional test to cover this behavior. You'll have to attach an application that reproduces the problem and re-open if you want us to take this issue further.

Show
Graeme Rocher added a comment - I've written an application that does:
def read = {
		def one = grailsApplication.config.test.value1
		def two = ConfigurationHolder.config.test.value2
		
		render "one = $one, two = $two"
	}
And it works fine in both WAR and run-app. I have however committed a functional test to cover this behavior. You'll have to attach an application that reproduces the problem and re-open if you want us to take this issue further.
Hide
Mark Stetzer added a comment -

Reproduced this problem on a sample application this morning. Will attach the application.

Running "grails clean && grails run-war" results in:

Running Grails application..
log4j:ERROR Error initializing log4j: Cannot get property 'db' on null object
java.lang.NullPointerException: Cannot get property 'db' on null object
at DataSource$_run_closure1.doCall(DataSource.groovy:5)
at DataSource$_run_closure1.doCall(DataSource.groovy)
at DataSource.run(DataSource.groovy:3)
at grails.web.container.EmbeddableServer$start.call(Unknown Source)
at _GrailsRun_groovy$_run_closure5_closure11.doCall(_GrailsRun_groovy:145)
at _GrailsRun_groovy$_run_closure5_closure11.doCall(_GrailsRun_groovy)
at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:274)
at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:137)
at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
at _GrailsRun_groovy.runWar(_GrailsRun_groovy:115)
at _GrailsRun_groovy.this$4$runWar(_GrailsRun_groovy)
at _GrailsRun_groovy$_run_closure3.doCall(_GrailsRun_groovy:72)
at RunWar$_run_closure1.doCall(RunWar.groovy:49)
at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
...

Show
Mark Stetzer added a comment - Reproduced this problem on a sample application this morning. Will attach the application. Running "grails clean && grails run-war" results in: Running Grails application.. log4j:ERROR Error initializing log4j: Cannot get property 'db' on null object java.lang.NullPointerException: Cannot get property 'db' on null object at DataSource$_run_closure1.doCall(DataSource.groovy:5) at DataSource$_run_closure1.doCall(DataSource.groovy) at DataSource.run(DataSource.groovy:3) at grails.web.container.EmbeddableServer$start.call(Unknown Source) at _GrailsRun_groovy$_run_closure5_closure11.doCall(_GrailsRun_groovy:145) at _GrailsRun_groovy$_run_closure5_closure11.doCall(_GrailsRun_groovy) at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:274) at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy) at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:137) at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy) at _GrailsRun_groovy.runWar(_GrailsRun_groovy:115) at _GrailsRun_groovy.this$4$runWar(_GrailsRun_groovy) at _GrailsRun_groovy$_run_closure3.doCall(_GrailsRun_groovy:72) at RunWar$_run_closure1.doCall(RunWar.groovy:49) at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324) at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334) at gant.Gant$_dispatch_closure6.doCall(Gant.groovy) ...
Hide
Mark Stetzer added a comment -

Sample application that should reproduce this problem. Run with "grails run-war" to see the error.

Show
Mark Stetzer added a comment - Sample application that should reproduce this problem. Run with "grails run-war" to see the error.
Hide
Graeme Rocher added a comment -

The issue in the attached application is that you're trying to read values in the Config.groovy file from the DataSource.groovy. I have fixed it so that ConfigurationHolder is set in after parsing the Config.groovy file so you will not get the NPE.

However, both these files are loaded after each other and before any external resources are used so you won't be able to do what you are doing in the attached sample anyway. If you want to store the db properties in an external file you should specify them like

dataSource.username=blah

In the same format as in DataSource.groovy and then they will be overridden by the external file

Show
Graeme Rocher added a comment - The issue in the attached application is that you're trying to read values in the Config.groovy file from the DataSource.groovy. I have fixed it so that ConfigurationHolder is set in after parsing the Config.groovy file so you will not get the NPE. However, both these files are loaded after each other and before any external resources are used so you won't be able to do what you are doing in the attached sample anyway. If you want to store the db properties in an external file you should specify them like dataSource.username=blah In the same format as in DataSource.groovy and then they will be overridden by the external file
Hide
Reiner Saddey added a comment -

See GRAILS-5856 for Grails 1.2.1

Show
Reiner Saddey added a comment - See GRAILS-5856 for Grails 1.2.1

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: