Home Grails, will different package on bootstrap leads creating user unsuccessful?
Reply: 1

Grails, will different package on bootstrap leads creating user unsuccessful?

Trainee
1#
Trainee Published in 2018-02-05 11:10:38Z

I am trying to create some user for login testing. So that, I have created some user on bootstrap.

User user = new User(username: 'user', userPassword: 'user', userEmail: 'user@user.com').save()

Then I try to login. The result was unsuccessful. Even database got no record on the user I have create on BootStrap.groovy

Will different package on bootstrap with my domains that affects?

Domain Package

package com.abc.myapp

BootStrap Package

package myapp

or is there any other possibility on this "bootstrap creating user error"

Sayem
2#
Sayem Reply to 2018-02-05 12:25:10Z

Bootstrap is not related to package.This file can be used for any custom logic you want to happen during application startup.Excellent use of the file is to preload some data in our database.

 class BootStrap { 
            def init = { servletContext ->
            new User(username:'user',userPassword:'user',userEmail:'user@user.com').save(failOnError: true)
                      }
}

save(failOnError: true) will give you the cause if it fails to save data.To avoid duplicate data creation use constrain in you domain class .

static constraints = {
        username unique: true, blank: false
        } 
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.312371 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO