war file generated by Grails ignores dataSource UR

2019-07-19 23:34发布

问题:

Grails version :1.1

Tomcat version: 5.5

The problem: The application doesn't use the URL data sources.

It seems like - it is using some other data source- but it doesn't seem to be in memory DB- since I can see the data persisted between sessions.

I have even tried giving a non -existant database name -and the application works fine. By that I mean that I am able to persist the data and fetch it fine- in the application I am unable to figure out where the data is getting persisted !!!

I generated the war file using the command- grails war

This is how the dataSource config looks like

 dataSource {

    pooled = true

    driverClassName = "com.mysql.jdbc.Driver"

    username = "user"

    password = "pwd"

 }

 hibernate {

    cache.use_second_level_cache=true

    cache.use_query_cache=true

    cache.provider_class='com.opensymphony.oscache.hibernate.OSCacheProvider'

 }

 environments {

    production {

        dataSource {

            dbCreate = "create" 

            url = "jdbc:mysql://localhost:3307/mydb?autoReconnect=true"

            dialect = org.hibernate.dialect.MySQL5Dialect

        }

    }

 }  

回答1:

You need to set a production data source since that's what grails uses when generating a war.


development {

        dataSource {

                dbCreate = "create" 

                url = "jdbc:mysql://localhost:3307/mydb?autoReconnect=true"

                dialect = org.hibernate.dialect.MySQL5Dialect
}
        }

production {

        dataSource {

                dbCreate = "create" 

                url = "jdbc:mysql://localhost:3307/mydb?autoReconnect=true"

                dialect = org.hibernate.dialect.MySQL5Dialect
}
        }



回答2:

What evidence are you looking at that tells you Grails is ignoring your data source?

Did you go into MySQL prior to running Grails to create mydb, add a user with "usr" and "pwd", and GRANT appropriate permissions? Grails doesn't do that for you.

Once the database exists, Grails will create the schema for you. You should be able to log in, use mydb, and "show tables" to see the schema.

But you have to create the database first.