SSH integration, very detailed SSH integration

Source: Internet
Author: User
Tags aop mysql version xmlns ssh tomcat log4j

SSH integration, very detailed SSH integration

This is a simple project for the eclipse-based MAVEN integration Struts2-spring-hibernate

1, first create a MAVEN project as follows: Name can be named by itself


Create the following diagram as follows:

will give an error, why? Because this is an incomplete MAVEN project, the Web. XML is missing.

Right click on the project, the following actions, will automatically complete the Web. xml file


The completion is shown in the following figure:

, it's good to have a complete maven skeleton.

2, the relevant jar package and Tomcat 7 plug-in required to import SSH to Pom.xml

<!--import SSH--

<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
<modelVersion>4.0.0</modelVersion>
<groupId>com.struts2-spring-hibernate.zh</groupId>
<artifactId>struts2-spring-hibernate.zh</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>ssh</name>
<description> This is a struts2-spring-hibernate integration </description>
<!--import SSH--
<!--Spring ORM Web Test JDBC TX hibernate c3p0 mysql driver struts spring-struts--
<properties>
<!--Spring Version---
<spring.version>3.2.12.RELEASE</spring.version>
<!--Hibernate version---
<!--STRTUS2 version---
<struts2.version>2.3.15.3</struts2.version>
<!--the version required for SLF4J logs--
<slf4j.version>1.7.5</slf4j.version>
<!--c3p0 Connection pool version--
<c3p0.version>0.9.1.2</c3p0.version>
<!--MySQL version---
<mysql.version>5.0.8</mysql.version>
<!--servlet versions--
<servlet.version>2.5</servlet.version>
<!--JSP version--
<jsp.version>2.0</jsp.version>
<!--junit Unit test version--
<junit.version>4.11</junit.version>
</properties>
<dependencies>
<dependency>
<!--Spring--
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>

<!--Hibernate--
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!--the version required for SLF4J logs--
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!--c3p0 Connection pool--
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>${c3p0.version}</version>
</dependency>
<!--MySQL--
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
<scope>runtime</scope>
</dependency>
<!--struts--
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>${struts2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>${struts2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-json-plugin</artifactId>
<version>${struts2.version}</version>
</dependency>
<!--struts Annotations development--
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>${struts2.version}</version>
</dependency>
<!--servlet related-
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>${jsp.version}</version>
<scope>provided</scope>
</dependency>
<!--unit Test--
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope><!--Testing is required--
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<port>80</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
</project>

</project>

Web. XML configuration file under 3,ssh

<?xml version= "1.0" encoding= "UTF-8"?>
<web-app xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xsi: schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version= " 2.5 ">

<display-name>struts2-spring-hibernate.zh</display-name>

<!--load local spring-related configuration Applicationcontext.xml, this is used here, of course, you can also name yourself as Spring.xml-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!--spring's listener--
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


<!--Struts2 's core configuration struts2.dispatcher-->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<!--struts Maps--
<filter-mapping>
<filter-name>struts2</filter-name>
<!--struts2 Map intercept--
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>

</welcome-file-list>

</web-app>

Configuration of the 4,log4j log

Log4j.appender.stdout=org.apache.log4j.consoleappender
Log4j.appender.stdout.target=system.out
Log4j.appender.stdout.layout=org.apache.log4j.patternlayout
log4j.appender.stdout.layout.conversionpattern=%d%5p (%c:%l)-%m%n

Log4j.rootlogger=info, stdout

5, database connection information configuration

Driver=com.mysql.jdbc.driver
Url=jdbc:mysql://localhost:3306/demo?useunicode=true&characterencoding=utf-8
User=root

passwd=123456

6, configure Applictioncontext.xml as follows

<?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:context= "Http://www.springframework.org/schema/context"
xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"
Xmlns:jpa= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/DATA/JPA"
xmlns:tx= "Http://www.springframework.org/schema/tx"
Xsi:schemalocation= "Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context.xsd
Http://www.springframework.org/schema/aop
Http://www.springframework.org/schema/aop/spring-aop.xsd
Http://www.springframework.org/schema/tx
Http://www.springframework.org/schema/tx/spring-tx.xsd
Http://www.springframework.org/schema/data/jpa
Http://www.springframework.org/schema/data/jpa/spring-jpa.xsd ">


<!--
<context:component-scan base-package= "Com.demo.usermanager" ></context:component-scan>
@Service @Con @Res @Aut @Com
-
<!--Scan Package Transaction package, here is the basic package for scanning, as long as the prefix is the same, it will be scanned by spring--

<context:component-scan base-package= "Com.demo.usermanager" > </context:component-scan>
<!--activate JPA interface Registration Spring Data JPA provides the implementation class, here is the JPA method provided by Hibernate---
<jpa:repositories base-package= "Com.demo.usermanager.dao"/>
<!--Sprin container to load local JDBC configuration--
<context:property-placeholder location= "Classpath:jdbc.properties"/>
<!--sprin container configuration c3p0 Connection Pool--
<bean id= "DataSource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" >
<property name= "Driverclass" value= "${jdbc.driverclass}" ></property>
<property name= "Jdbcurl" value= "${jdbc.url}" ></property>
<property name= "user" value= "${jdbc.username}" ></property>
<property name= "Password" value= "${jdbc.password}" ></property>
</bean>
<!--entitymanagerfactory Effect: Similar sessionfactory need to inject connection pool--
<bean id= "Entitymanagerfactory" class= "Org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" >
<property name= "DataSource" ref= "DataSource"/>
<!--scan entity class entity class Registration--
<property name= "Packagestoscan" value= "Com.demo.usermanager.domain"/>
<property name= "Jpavendoradapter" >
<bean class= "Org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" >
<property name= "Database" value= "ORACLE"/>
<property name= "Generateddl" value= "true"/>
<property name= "Showsql" value= "true"/>
<property name= "Databaseplatform" value= "${jdbc.dialect}"/>
</bean>
</property>
</bean>
<!--JPA transaction management, where transactions are managed using JPA--
<bean id= "TransactionManager" class= "Org.springframework.orm.jpa.JpaTransactionManager" >
<property name= "Entitymanagerfactory" ref= "Entitymanagerfactory"/>
</bean>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.