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

jaxb example

Download <strong>eclipselink.jar</strong>,

 Create a java project and add a class in it.Now create a properties file




 package pck;

 import javax.xml.bind.JAXBContext;

 import javax.xml.bind.Marshaller;

 import javax.xml.bind.annotation.XmlElement;

 import javax.xml.bind.annotation.XmlRootElement;

 import net.sf.json.JSONException;

 @XmlRootElement (name="Person")

 public class Person {

 @XmlElement (name="age")

 public int age;

 @XmlElement (name="name")

 public String name;

 public static void main(String[] args) throws JSONException, Exception {

 Person me = new Person();

 me.age = 27; = "Biswajit";


 JAXBContext jc = JAXBContext.newInstance(Person.class);

 Marshaller marshaller = jc.createMar…