Spring Hibernate Solution

June 15th, 2011
Comments Off

Content about : Spring Hibernate Solution

Advertisements


My First Project to Guide Newbie for Create Simply J2ee Project With Spring Frame work
* Using Hibernate
* Create WebService
* Interceptor
* Working with DTO
* Master for Model and Controller

Download Source with Eclipse project (Coming soon)


Step by Step to Create Spring J2EE Web Application

admin Development, My Spring Hibernate Solution ,

Spring Webservice Example for Create Webservice with apache CXF and Spring Framework

June 15th, 2011
Comments Off

Content about : Spring Webservice with apache CXF
Advertisements


In the Last content for this project in my spring hibernate solution i need to provide WebService with Spring framework
You can create service simply with 2 step

First Step Create Service Class
**Interface
package com.en.ws;
import javax.jws.WebParam;
import javax.jws.WebService;
import com.en.dto.ExampleDto;
/**
* @author Somsuksri Kasemsuk
* @version 1.0 $Id: ExampleWSInf.java 2693 2009-07-03 $
*/
@WebService
public interface ExampleWSInf {
public ExampleDto getData(@WebParam(name=”codeId”)String codeId);
}

**Implements Class
package com.en.ws;
import java.io.Serializable;
import com.en.dto.ExampleDto;
import com.en.model.MasterModel;
//@WebService(endpointInterface = “com.en.ws.ExampleWSInf”, serviceName = “ExampleWS”, portName=”ExampleWS”)
public class ExampleWS  implements ExampleWSInf,Serializable {
private static final long serialVersionUID = 1L;
private MasterModel model;
public ExampleDto getData(String codeId){
ExampleDto dto=(ExampleDto)model.getDataObj(new Integer(codeId));
return dto;
}
public MasterModel getModel() {
return model;
}
public void setModel(MasterModel model) {
this.model = model;
}

}

XML Mapping for Spring framework work together with Apache CXF
<?xml version=”1.0″ encoding=”UTF-8″?>
<beans xmlns=”http://www.springframework.org/schema/beans”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:jaxws=”http://cxf.apache.org/jaxws”
xsi:schemaLocation=”http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd”>

<!– Load CXF modules from cxf.jar –>
<import resource=”classpath:META-INF/cxf/cxf.xml” />
<import resource=”classpath:META-INF/cxf/cxf-extension-soap.xml” />
<import resource=”classpath:META-INF/cxf/cxf-servlet.xml” />

<bean id=”exampleWS” class=”com.en.ws.ExampleWS”>
<property name=”model” ref=”exampleModel”/>
</bean>
<jaxws:endpoint id=”EXAMPLEWS”
implementorClass=”com.en.ws.ExampleWS”
implementor=”#exampleWS”
address=”/example” />
</beans>

admin Development

Spring WEB.xml Start up Spring Engine Load it in Web.xml

June 15th, 2011
Comments Off

Content about : Spring WEB.xml
Advertisements


After you made all of Class eg Hibernate ,DTO , Model ,Controller and made all of XML Configuration eg. Datasource XML ,Hibernate XML,Servlet XML you need to add all to Load it in WEB.xml  Lest go to Start Spring Engine Now !!
Example Web.xml for Start Spring
<?xml version=”1.0″ encoding=”UTF-8″?>
<web-app id=”WebApp_ID” version=”2.4″
xmlns=”http://java.sun.com/xml/ns/j2ee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xmlns:c=”http://java.sun.com/jsp/jstl/core”
xmlns:fmt=”http://java.sun.com/jsp/jstl/fmt”
xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”>

<display-name>EnterprisePT</display-name>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>EnterprisePT.root</param-value>
</context-param>
<!– log4j configuration in web.xml –>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

<!– /log4j configuration in web.xml END –>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/appcontext/datasource-service.xml
/WEB-INF/appcontext/dataAccesssContext-Hibernate.xml
/WEB-INF/appcontext/view-servlet.xml
/WEB-INF/appcontext/applicationCfxContext-WS.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>appcontext/view</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>appcontext/view</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>

admin Development , ,