Grails + Spring Security + MySQL installation
Installing Grails is simple, easy and allows you to start developing in a matter of minutes.
But I'll be adding a bit more complexity to this tutorial so that you aren't left at the end of the day going.. right.. Now WTF?
(Don't know what Grails is? Check out What is Grails for more info)
Downloads
The following file is required for this tutorial
The following files are recommended
- Mysql Java Connector (file required to make sql work with grails)
- Mysql Essential - (the actual sql server)
- Mysql Workbench (GUI interface)
Installation
Step 1 : Grails Installation
Install Grails by following these instructions (there is no need for me to repeat this here)
Just don't forget to set GRAILS_HOME and JAVA_HOME in your 'System variables'
Once those steps are complete, open up Command Prompt or your Favourite IDE and do the following :
Browse to your GRAILS_HOME directory
$ grails create-app plant-store
Grails will now install all the necessary files required for this web-app to run.
The only problem we now have is that Grails comes with an in-memory database.
Now, I understand from a ease-of-use point of view that this is useful, but honestly, it is just plain awful when you are trying to understand how things are put together from the database side of things.
Step 2 : Mysql Installation
First thing you need to do is copy the mysql-connector-java-(vernumber)-bin.jar file into your GRAILS_HOME/plant-store/lib folder.
Next you will need to configure your DataSource.groovy file, which is found in plant-store/grails-app/conf
- Open up DataSource.groovy
- Change your dataSource to read as follows :
dataSource { pooled = true driverClassName = "com.mysql.jdbc.Driver" username = "root" password = "password" dialect = "org.hibernate.dialect.MySQL5InnoDBDialect" } - Change the url's in your environments to the following : url = "jdbc:mysql://localhost/{databasename}"
Finally, we install the Spring Security Core Plugin
Before we start doing this, let me explain to you what Spring Security Core Plugin is.
Spring Security Core makes use of all the work the guys over at Spring have done on Spring Security and turned it into a plugin for Grails.
What this means is that you can now install the plugin by typing the following inside plant-store directory :
grails install-plugin spring-security-core
grails s2-quickstart plant.store User Role Requestmap
And so in less than 30mins you have :
- Installed a Web-App Platform
- Linked it with a MySql database
- Installed a Security Controller that will be managing all your users!
Easy yeah?
Later this week I'll be covering the basics of Grails, which involves controllers, bootstrapping and who knows what else I'll have learnt