Can I configure Grails with no datasource?
Asked Answered
F

4

25

I have a Grails app that loads its data from xml files and delivers rss feeds via rome. I don't have any domain classes and my app has no datasource. I don't want Grails to load an in memory hsql db when the application has no need for it. Deleting the DataSource.groovy file prevents me from launching the web app, it seems as though the datasource is required, but is there anything I can do if my application doesn't need a datasource?

Filling answered 27/8, 2009 at 21:58 Comment(0)
R
21

The following steps work for a new app (Grails 1.1.1) to run without using a datasource:

grails create-app nodb
cd nodb
grails uninstall-plugin hibernate
rm grails-app/conf/DataSource.groovy
grails create-controller Foo
<add "render "hi bar" to the index closure of ./grails-app/controllers/FooController.groovy>
grails run-app
http://localhost:8080/nodb/foo - prints hi bar

For an existing app on at least version 1.1 (think that's when hibernate was made a plugin) you should be able to just uninstall-plugin and delete the DataSource.groovy file.

Radiology answered 6/9, 2009 at 21:51 Comment(1)
With newer versions of grails you need to comment out the plugin in BuildConfig.groovy instead of running uninstall-plugin. Also, you can just comment out the lines in DataSourcey.groovy as @Jared suggests in another answer.Civilly
E
6

I was able to comment out the data source and get a default grails app to run. Comment out your production section in the same way I commented out the following code in datasource.groovy


/*  development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop','update'
            url = "jdbc:hsqldb:mem:devDB"
        }
    }*/

I was also able to remove the hibernate plugin using "grails uninstall-plugin hibernate" and still have the default app run. I haven't done extensive testing with this but hopefully this works for you.

Effeminize answered 28/8, 2009 at 3:12 Comment(0)
A
4

The in-memory database is very lightweight so you should stick with that if you don't need a real database.

Aerialist answered 28/8, 2009 at 2:50 Comment(2)
We've run into a similar problem. Deploying more then one grails app on the same tomcat instance with the default datasource settings does not work. I believe this is because the hSQL instances use the same on disk lock files or something.Bootie
Yeah, the default production datasource uses an hql file datastore. You can't use the same file name for more than 1 grails app, so you need to change the database name in the datasource. It's pretty annoying. Being able to just not have a datasource would still be preferable. Even if it's lightweight, if you're not going to use it why have it there.Filling
M
2

This is a good guide: http://digitalbreed.com/2011/using-grails-without-a-database

Remove Grails’ Hibernate plugin.

  1. grails uninstall-plugin hibernate
  2. Delete the datasource configuration file conf/DataSource.groovy
  3. Explicitly declare services as non-transactional. The default is true and your class methods would be proxied, but without the Hibernate plugin there is no transaction manager and the deployment will fail.

    class SomeService { static transactional = false // ... }

  4. Use command objects instead of domain objects, particularly if you need validation.

Marolda answered 12/8, 2015 at 22:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.