Spring + JPA + jqGrid Maven Archetype

2011-09-04  来源:本站原创  分类:Internet  人气:260 

This is a maven archetype of spring + jpa + jqgrid

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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>Spring+JPA+jqGrid</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/config/spring/application-context.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/</url-pattern>
    </filter-mapping>

    <servlet>
        <servlet-name>spring-servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/config/spring/spring-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>spring-servlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

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

spring-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="trent.yang.springjpa.example.controller" />

    <mvc:annotation-driven />

    <mvc:resources mapping="/resources/css/**" location="/resources/css/" />
    <mvc:resources mapping="/resources/js/**" location="/resources/js/" />
    <mvc:resources mapping="/*.html" location="/" />

</beans>

application-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <!--  Database Start -->
    <context:property-placeholder location="/WEB-INF/config/database.properties" />

    <bean>
        <property name="driverClass" value="${connection.driverClass}" />
        <property name="jdbcUrl" value="${connection.url}" />
        <property name="user" value="${connection.user}" />
        <property name="password" value="${connection.password}" />
        <property name="acquireIncrement" value="${c3p0.acquireIncrement}" />
        <property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}" />
        <property name="initialPoolSize" value="${c3p0.initialPoolSize}" />
        <property name="minPoolSize" value="${c3p0.minPoolSize}" />
        <property name="maxPoolSize" value="${c3p0.maxPoolSize}" />
        <property name="maxStatements" value="${c3p0.maxStatements}" />
    </bean>

    <bean>
        <property name="databasePlatform" value="${hibernate.dialect}" />
    </bean>

    <bean
       >
        <property name="persistenceXmlLocation" value="/WEB-INF/config/jpa/persistence.xml" />
        <property name="persistenceUnitName" value="examplePersistenceUnit" />
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter" />
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
            </props>
        </property>
    </bean>

    <!--  Database End -->

    <!-- Transaction Start -->
    <bean>
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
     <!--
    <tx:advice transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="*" />
        </tx:attributes>
    </tx:advice>

    <aop:config>
        <aop:pointcut expression="execution(* trent.yang.springjpa.example.service.*.*(..))" />
        <aop:advisor pointcut-ref="servicePointcut" advice-ref="txAdvice" />
    </aop:config>
    -->
    <tx:annotation-driven transaction-manager="transactionManager" />
    <!-- Transaction End -->

    <!-- Service Start -->
    <context:component-scan base-package="trent.yang.springjpa.example.service.impl" />
    <!-- Service End -->

    <!-- DAO Start -->
    <context:component-scan base-package="trent.yang.springjpa.example.dao.impl" />
    <!-- DAO End -->

</beans>

database.properties

#Mysql database connection setting
connection.driverClass=com.mysql.jdbc.Driver
connection.url=jdbc:mysql://localhost:3306/example?zeroDateTimeBehavior=convertToNull
connection.user=root
connection.password=root

#Hibernate setting
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.format_sql=true

#c3p0 connection pool setting
c3p0.acquireIncrement=1
c3p0.idleConnectionTestPeriod=200
c3p0.initialPoolSize=1
c3p0.minPoolSize=1
c3p0.maxPoolSize=5
c3p0.maxStatements=0

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    version="1.0">
    <persistence-unit name="examplePersistenceUnit">
        <!--<provider>org.hibernate.ejb.HibernatePersistence</provider>-->
        <!-- <jar-file>/WEB-INF/lib/example-model*.jar</jar-file> -->
        <class>trent.yang.springjpa.example.model.Product</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
    </persistence-unit>
</persistence>

index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" >
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Spring+JPA+jqGrid</title>
    <link href="resources/css/ui-lightness/jquery-ui-1.8.16.custom.css" type="text/css" rel="stylesheet" />
    <link href="resources/css/ui.jqgrid.css" media="screen" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="resources/js/jquery-1.6.2.js"></script>
    <script type="text/javascript" src="resources/js/jquery-ui-1.8.16.custom.js"></script>
    <script type="text/javascript" src="resources/js/i18n/grid.locale-en.js"></script>
    <script type="text/javascript" src="resources/js/jquery.jqGrid.src.js"></script>
    <script type="text/javascript">
    $(document).ready(function($) {
        $("#list").jqGrid({
            url: 'products',
            datatype: "json",
            colNames: ['Product Id','Product Name', 'Product Description'],
            colModel: [
                      {name: 'id', index: 'id', width: 100},
                      {name: 'name', index: 'name', width: 120},
                      {name: 'description', index: 'description', width: 200}
                      ],
            jsonReader: {repeatitems: false, id: "0"},
            rowNum: 10,
            rowList: [10, 20, 30],
            pager: '#pager',
            sortname: 'id',
            viewrecords: true,
            sortorder: "desc",
            caption: "Products"
        });
        $("#list").jqGrid('navGrid','#pager', {edit: false, add: false, del: false, search: false});
    });
    </script>
  </head>
  <body>
    <div>
      <table></table>
      <div></div>
    </div>
  </body>
</html>

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>${groupId}</groupId>
    <artifactId>${artifactId}</artifactId>
    <version>${version}</version>
    <packaging>war</packaging>
    <properties>
        <spring.version>3.0.5.RELEASE</spring.version>
        <slf4j.version>1.6.1</slf4j.version>
    </properties>
    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</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-aop</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
            <scope>test</scope>
        </dependency>

        <!-- Hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>3.6.0.Final</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.1.0.Final</version>
        </dependency>

        <!-- MySql Connector -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.13</version>
        </dependency>

        <!-- C3P0 Pool -->
        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.2</version>
        </dependency>

        <!-- Jackson JSON Processor -->
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.8.1</version>
        </dependency>

        <!-- AspectJ -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.6.9</version>
        </dependency>

        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${slf4j.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
            <scope>runtime</scope>
        </dependency>

        <!-- Junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <version>1.1</version>
                <configuration>
                    <server>tomcat</server>
                    <path>/example</path>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
相关文章
  • Spring + JPA + jqGrid Maven Archetype 2011-09-04

    This is a maven archetype of spring + jpa + jqgrid web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi

  • S2SJ (Struts2 + Spring + JPA) integration profile 2009-08-07

    S2SJ (Struts2 + Spring + JPA) integration profile 1.web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XML

  • JSF + Spring + JPA (Hibernate implementation) built environment (1) 2010-12-30

    Feelings before writing Liu Yan First said yes, say after the shortcomings of the article. JSF + Spring + JPA in my opinion, should be said that Struts2 + Spring + Hibernate alternative solutions. The introduction of JPA to replace or upgrade the pac

  • JSF + Spring + JPA (Hibernate implementation) of the environment to build (5) 2010-12-30

    5. After the change it faces-config.xml inside the content. Add the following <managed-bean> <managed-bean-name> playersVO </ managed-bean-name> <managed-bean-class> mangerTeam.vo.PlayersVO </ Managed-bean-class> <managed-

  • 解决spring jpa中配置文件报'jpa:repositories'的问题 2014-04-17

    一.问题描述 使用spring jpa,报no declaration can be found for element 'jpa:repositories'错误的解决方案 Multiple annotations found at this line: - cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'jpa:repositories'.

  • JPA+Spring+druid+hibernate+maven+resetlet 配置文件 2013-11-02

    记录: pom.xml <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"> &l

  • maven archetype: generate a better understanding of 2010-09-24

    It can be said a lot of time entangled With mvn archetyoe: generate will always be when the following conditions: Normal should be $ mvn archetype:generate [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'archetype

  • 第二步搭建完成:JSF(Primefaces)+SPRING+JPA(Hibernate) 2012-07-26

    不上图了,太麻烦,直接说具体的步骤. 1.首先挑选好对应的Hibernate jar包.下面我项目里的jar包是可以对应使用的.包没几个,就不再说了, 2.OK之后各种配置,伤脑筋,不想再说了.下面配置文件都有,方便就去copy改,基本上不需要改动什么了.想认知的,里面也有注释. 3.OK之后,推荐使用ui文件弄好模板文件,各种减少代码量. 4.写好基类,推荐使用泛型,代码不要太少了,看着service层空荡荡的都有点不习惯,基本操作类基本不需要再写什么代码了. 5.各种调试. 总结:这个框架,

  • Spring + JPA integration 2010-03-30

    Reference: Spring Recipes 1. Concerning the contents: * Configure JPA EntityManagerFactory in the Spring * Note declarative transaction configuration * Use JPA persistent objects into the context of 2. To achieve these steps: 0). Depends Package: hib

  • Spring + JPA deployment to Jboss problems 2010-12-02

    1. Remove the packages associated with the servlet 2. Remove xerces *. jar, xml-apis *. jar 3. Remove jboss-common-core package because the package already exists under JBoss 4 found that the database connection using localhost not, even can use 127.

  • JSF + Spring + JPA (Hibernate implementation) built environment (2) 2010-12-30

    Here in the WEB-INF added jsf_core.tld, html_basic.tld and tomahawk.taglib.xml file, create a faces-config.xml file, the contents of configuration is as follows: <! - Configure facelets -> <application> <locale-config> <default-locale

  • Maven Archetype Plugin 2011-05-18

    http://maven.apache.org/archetype/maven-archetype-plugin/ • archetype: create-from-project creates an archetype from an existing project. http://maven.apache.org/archetype/maven-archetype-plugin/create-from-project-mojo.html Archetype of the command

  • the maven archetype: create error when 2011-06-30

    Today the following maven command to create the project, mvn archetype:create -DgroupId=com.nuc.test -DartifactId=mytest Reported the following error: Reason: Error getting POM for 'org.apache.maven.plugins:maven-archetype-plugin' from the repository

  • Spring SpringMVC Junit Maven下整合教程 2013-07-28

    1.开始搭建我的环境吧.首先,IDE我用的是eclipse的JEE版本.要保证装上了Maven哟,可以使用eclipse的Install New Software,URL地址是http://m2eclipse.sonatype.org/sites/m2e/,然后一步步走下去,安装好了过了会重启一次. maven 只要解压好后 配置一下环境变量 给一个忠告哟,安装好了maven后,不要使用IDE里面的了,而是去官方下载一个,解压,然后让IDE的Maven指向你下载安装的,如图: <project

  • Spring+Mybatis+MySql+Maven 简单的事务管理案例 2014-01-23

    本案例代码主要结构如图: 1.数据库脚本 -- ---------------------------- -- Table structure for `user` -- ---------------------------- DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `id` varchar(20) NOT NULL, `name` varchar(20) default NULL, PRIMARY KEY (`id`) ) ENG

  • Spring + JPA + Struts2 developers 2010-02-14

    The first step: in the class path following the establishment of a META-INF folder, and note that this name must not be arbitrarily changed, and then the establishment of a persistence.xml file, configure the template as follows: <? xml version = "

  • Dwr + struts2.0 + spring + jpa 2008-06-02

    1. The important thing is that if used Dwr, can not be used for injecting Spring. This points to note: public class RatingAction extends AbstractAction{ private double avg_rating ; private static IRatingService getRatingService() { ControllerFactory

  • Spring + JPA + atomikos实现Oracle + SQL Server 2011-07-29

    persistence.xml <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLoc

  • 第一步搭建:JSF(Primefaces)+SPRING+JPA(Hibernate) 2012-07-11

    公司采用的JSF是primefaces,这个前端MVC框架,个人用的觉得还是蛮不错的,虽然也存在很多不足,但也掩盖不了他的优势,题外话,这货是土耳其的. = =! 总体会用到的东西: 1.primefaces版本3.2. 2.jsf morraja 3.Maven3.0.3 总体环境:http://blog.csdn.net/lioncredo/article/details/7385870 3.apache-tomcat-7.0.23 第一步搭建和后台无关 照常建立maven工程 如图操作 接

  • 32.Struts + Spring + JPA integration 2010-03-31

    Because I do not have Struts1, so I do not write notes