Skip to content

Instantly share code, notes, and snippets.

@rohman
Created April 11, 2013 23:47
Show Gist options
  • Save rohman/5368145 to your computer and use it in GitHub Desktop.
Save rohman/5368145 to your computer and use it in GitHub Desktop.
Ulang Spring mvc Service MainClass
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ulang.springservice;
import id.web.rohman.ulangspringservice.model.Tamu;
import id.web.rohman.ulangspringservice.service.api.TamuService;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
*
* @author syahril
*/
public class UlangSpringservice {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
// TODO code application logic here
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{
"classpath*:id/**/applicationContext.xml"
});
generate(ctx);
Tamu t = new Tamu();
t.setName("Syahril");
t.setAddress("Condet");
t.setEmail("aa@aa.com");
TamuService tamuService = (TamuService) ctx.getBean("tamuService");
tamuService.saveTamu(t);
}
private static void generate(ApplicationContext ctx) throws SQLException{
DataSource dS = (DataSource) ctx.getBean("dataSource");
Connection con = dS.getConnection();
Configuration configuration = new AnnotationConfiguration().configure("id/web/rohman/ulangspringservice/config/hibernate.cfg.xml");
configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5InnoDBDialect");
new SchemaExport(configuration,con).create(true, true);
con.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment