Skip to main content

Starting spring roo

How to create a spring roo application and deploy it in Jboss 7 Database: Mysql

 I am using jdk1.6 and java compliance 1.5 and spring IDE.  

 Step 1: create new spring roo project jpa set up

 roo> jpa setup --provider HIBERNATE --database MYSQL

 Now create entity object

 roo> entity jpa --class --testAutomatically

 Create field in entity object

 roo> field string --cityname message --notNull web mvc set up in roo shell

 roo> web mvc setup roo> web mvc all --package ~.web  
 deployment in Jboss 7  
 change persistence.xml 
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <persistence xmlns="" xmlns:xsi="" version="2.0" xsi:schemaLocation="">
 <persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL"> 
 <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
 <!-- value="create" to build a new database on each run; value="update" to modify an existing database; 
 value="create-drop" means the same as "create" but also drops tables when Hibernate closes; value="validate" makes no changes to the database -->
 <property name="" value="create"/>
 <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/> 
 <property name="hibernate.connection.charSet" value="UTF-8"/> 
 <!-- Uncomment the following two properties for JBoss only --> 
 <property name="hibernate.validator.apply_to_ddl" value="false" /> 
 <property name="hibernate.validator.autoregister_listeners" value="false" />
 add new folder in modules->com->mysql->main and add mysql connector jar in main folder create another module.xml file in main folder
 <?xml version="1.0" encoding="UTF-8"?>
 <module xmlns="urn:jboss:module:1.1" name="com.mysql">
 <resources> <resource-root path="mysql-connector-java-5.1.22-bin.jar"/> </resources>
 <dependencies> <module name="javax.api"/> <module name="javax.transaction.api"/> 
 <module name="javax.servlet.api" optional="true"/> </dependencies> </module>  
 Now add new datasource tag in standalone.xml in Jboss 
 <datasource jndi-name="java:jboss/datasources/myds" pool-name="myds" enabled="true" use-java-context="true"> 
 <driver>mysql</driver> <security> <user-name>root</user-name> <password>admin</password> </security> </datasource> 
 add new driver <driver name="mysql" module="com.mysql"> <xa-datasource-class>com.mysql.jdbc.Driver</xa-datasource-class> </driver> 
 now deploy the war file and start Jboss


Popular posts from this blog

jdbc mysql example in java

Here’s an example to show you how to connect to MySQL database via a JDBC driver.To connect to MySQL from Java, you have to use the JDBC driver from MySQL. You find the latest MySQL JDBC driver under the following URL:
Create a example database and named it test.Now create a a table name it user. Create table user ((userid INT NOT NULL AUTO_INCREMENT,
username VARCHAR(30) NOT NULL, PRIMARY KEY (userid)); Now add the record in your table; Now create a project in eclipse and mysql-connector jar in its classpath.package com.test;
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; publicclass JavaJDBCExample { private Connection connect = null; private Statement statement = null; private ResultSet resultSet = null; publicvoid readDatabase() { try { // this will load the MySQL driver Class.forName("com.mysql.jdbc.Driver"); // setup the connection wi…

singleton design pattern

Java Singleton design pattern is one of the design pattern which suggest that only one instance of a Singleton object is created by the JVM. This is useful when exactly one object is needed to coordinate actions across the system Example: public class Singleton{ privatestatic Singleton singleton = null; private Singleton(){ } publicstaticsynchronized Singleton getInstance( ) { if(singleton == null) { singleton = new Singleton(); } returnsingleton; } publicvoid test( ) { System.out.println("test"); } @Override protected Object clone() throws CloneNotSupportedException { // TODO Auto-generated method stub returnnew CloneNotSupportedException(); } } publicclass SingletonTest { publicstaticvoid main(String[] args){ Singleton singleton = Singleton.getInstance(); try{ Singleton

Tomcat configuration

1. How to deploy web application in tomcat 
 Create a war file and deploy it in tomcat->webapps folder.Restart tomcat and write localhost:8080/YOURWEBAPPNAME. 
 2. Add jndi in tomcat 
 <Resource name="jdbc/myDB" auth="Container"
 type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000"
 username="admin" password="admin"
 in web.xml 
 <description>DB Connection</description>
 3. Add user with manager role in tomcat   Tomcat-users.xml 
 <role rolename="manager"/>
 <user username="admin"…