spring + jdbc + extjs configuration
所有源代码能够訪问我的GitHub
有空没空的稻谷了几天,最终前后台跑通了,提供一套可用的配置文件。
(因为与extjs整合,spring security的登录须要重写原handler。会在后面补上)
首先是pom。主要有junit。spring(mvc + security)。log4j以及jdbc(mysql)依赖。
<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>com.paris</groupId>
<artifactId>fast-contacts</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>fast-contacts Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<jstl.version>1.2</jstl.version>
<junit.version>4.11</junit.version>
<spring.version>4.0.0.RELEASE</spring.version>
<servlet.version>3.0.1</servlet.version>
<jsp.version>2.2</jsp.version>
<tomcat.plugin.version>2.2</tomcat.plugin.version>
<slf4j.version>1.5.6</slf4j.version>
<spring.security.version>3.2.4.RELEASE</spring.security.version>
<lombok.version>1.12.6</lombok.version>
<log4j.version>1.2.16</log4j.version>
<org.json.version>20090211</org.json.version>
<common.dbcp.verison>1.4</common.dbcp.verison>
<commmons.pool.version>1.6</commmons.pool.version>
<mysql.connector.verison>5.1.6</mysql.connector.verison>
</properties> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>${jsp.version}</version>
<scope>provided</scope>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</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-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- spring webmvc相关jar包 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- spring security configuration -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>${common.dbcp.verison}</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>${commmons.pool.version}</version>
</dependency> <!-- spring test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency> <!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<!-- log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency> <!-- org json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>${org.json.version}</version>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.connector.verison}</version>
</dependency>
</dependencies> <build>
<finalName>fast-contacts</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>${tomcat.plugin.version}</version>
<configuration>
<port>8080</port>
<path>/</path>
<uriEncoding>UTF-8</uriEncoding>
<url>http://localhost:8080/manager/html</url>
<server>tomcat7</server>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
</plugins>
</build>
</project>
web.xml 主要是spring和spring security。
我用的html。假设喜欢jsp的,能够去掉html的filterMapping
<?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_3_0.xsd"
version="3.0" metadata-complete="false">
<display-name>Fast contacts</display-name> <!--
- Location of the XML file that defines the root application context
- Applied by ContextLoaderListener.
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring-security.xml
classpath:spring-servlet.xml
</param-value>
</context-param> <!-- Nothing below here needs to be modified --> <context-param>
<param-name>webAppRootKey</param-name>
<param-value>servletapi.root</param-value>
</context-param> <filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter> <filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<!--bak <url-pattern>/*</url-pattern> -->
<url-pattern>/*</url-pattern>
</filter-mapping> <!--
- Loads the root application context of this web app at startup.
- The application context is then available via
- WebApplicationContextUtils.getWebApplicationContext(servletContext).
-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
spring-security.xml 不全,可是可用。
<?xml version="1.0" encoding="UTF-8"?>
<b:beans xmlns:b="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd"> <!-- no need to filter login page -->
<security:http pattern="/login" security="none"/>
<!-- 不要过滤图片等静态资源,当中**代表能够跨越文件夹。*不能够跨越文件夹。 -->
<security:http pattern="**.jpg" security="none" />
<security:http pattern="**.png" security="none" />
<security:http pattern="**.gif" security="none" />
<security:http pattern="**.css" security="none" />
<security:http pattern="**.js" security="none" />
<security:http auto-config="true">
<!--
<security:intercept-url pattern="/auth/login" access="permitAll"/>
<security:intercept-url pattern="/admin" access="hasRole('ROLE_ADMIN')"/> -->
<security:intercept-url pattern="/login.html" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<security:intercept-url pattern="/*" access="ROLE_USER"/>
<security:form-login
login-page="/login.html"
/>
<security:logout delete-cookies="JSESSIONID"/>
<security:remember-me key="fast-contacts"/>
<security:session-management invalid-session-url="/invalidSession.html"></security:session-management>
</security:http> <security:authentication-manager>
<security:authentication-provider user-service-ref="fastUserDetailsService">
<security:password-encoder ref="passwdEcoder"/>
<!--
<security:user-service>
<security:user name="test" password="test" authorities="ROLE_USER"/>
<security:user name="admin" password="admin" authorities="ROLE_USER,ROLE_ADMIN"/>
</security:user-service>-->
</security:authentication-provider>
</security:authentication-manager> <b:bean id="fastUserDetailsService"
class="com.chinadreamer.contacts.filter.FastUserDetailsService">
</b:bean>
<b:bean id="passwdEcoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder"/>
</b:beans>
spring-servlet.xml db连接是mysql driver + jdbc
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <!-- Scans the classpath of this application for @Components to deploy as
beans -->
<context:component-scan base-package="com.chinadreamer.contacts.*,demo.*">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<mvc:annotation-driven /> <!-- 静态资源映射 -->
<mvc:resources mapping="/comp/**" location="/WEB-INF/comp/"/>
<mvc:resources mapping="/pages/**" location="/WEB-INF/pages/"/>
<mvc:resources mapping="/resources/**" location="/WEB-INF/resources/"/>
<mvc:resources mapping="/view/**" location="/WEB-INF/view/"/> <!-- 对模型视图名称的解析。在请求时模型视图名称加入前后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/view/"
p:suffix=".html" /> <!-- 配置数据源 -->
<bean class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close"
id = "dataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/fastcontacts"></property>
<property name="username" value="root"/>
<property name="password" value="Password2"/>
<!-- 连接池启动时的初始值 -->
<property name="initialSize" value="10"/>
<!-- 连接池的最大值 -->
<property name="maxActive" value="60000"/>
<!-- 最大空暇值.当经过一个高峰时间后。连接池能够慢慢将已经用不到的连接慢慢释放一部分,一直降低到maxIdle为止 -->
<property name="maxIdle" value="20"/>
<!-- 最小空暇值.当空暇的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->
<property name="minIdle" value="5"/>
</bean>
<!-- transaction -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 事务拦截器 -->
<!-- 配置事务拦截器 -->
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="request*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>*Service</value>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
<property name="transactionInterceptor" ref="transactionInterceptor"/>
</bean> <!-- jdbc template -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean> </beans>
spring + jdbc + extjs configuration的更多相关文章
- Spring JDBC
转载:博客主页:http://blog.csdn.NET/chszs 一.概述 在Spring JDBC模块中,所有的类可以被分到四个单独的包:1)core即核心包,它包含了JDBC的核心功能.此包内 ...
- Springboot 系列(九)使用 Spring JDBC 和 Druid 数据源监控
前言 作为一名 Java 开发者,相信对 JDBC(Java Data Base Connectivity)是不会陌生的,JDBC作为 Java 基础内容,它提供了一种基准,据此可以构建更高级的工具和 ...
- springboot成神之——spring jdbc的使用
本文介绍spring jdbc的使用 目录结构 pom配置 properties配置 model层User类 Dao层QueryForListDao config层AppConfiguration 程 ...
- Spring JDBC 例子
http://www.yiibai.com/spring/spring_jdbc_example.html 要了解有关Spring JDBC框架与JdbcTemplate类的概念,让我们写这将实现所有 ...
- 4-9 基于Spring JDBC的事务管理(续)
10. 基于Spring JDBC的事务管理(续) 当需要方法是事务性的,可以使用@Transactional注解,此注解可以添加在: 接口 会使得此接口的实现类的所有实现方法都是事务性的 接口中的抽 ...
- 一文学会Spring JDBC 使用
Spring JDBC 1.JDBC JDBC 就是 数据库开发 操作的 代名词,因为只要是现代商业项目的开发那么一定是离不开 数据库 的,不管你搞的是什么,只要是想使用动态的开发结构,那么一定就是 ...
- spring jdbc 查询结果返回对象、对象列表
首先,需要了解spring jdbc查询时,有三种回调方式来处理查询的结果集.可以参考 使用spring的JdbcTemplate进行查询的三种回调方式的比较,写得还不错. 1.返回对象(queryF ...
- spring jdbc获取插入记录的主键id
在JDBC3.0规范中,当新增记录时,允许将数据库自动产生的主键值绑定到Statement或PreparedStatement中.使用Statement时,可以通过以下方法绑定主键值: int exe ...
- Spring JDBC实现查询
1 db.properties jdbc.user=root jdbc.password=920614 jdbc.driverClass=com.mysql.jdbc.Driver jdbc.jdbc ...
随机推荐
- 把自己的程序打成jar包,让别人调用
我们写程序的时候往往需要把自己的程序打包成jar包,给第三方调用.Eclipse让我们非常方便的可以导出jar包.但是当程序里需要用到res里的资源时,往往就会出现问题.因为统自动生成的R类如果被打 ...
- CSS 定位元素之 relative
1. relative 和 absolute relative 会限制 absolute. absolute 会根据 父级的的定位元素来定位. 2. overflow 和 absolue 当overf ...
- vmware下给linux添加硬盘
http://blog.csdn.net/robbie1314520/archive/2010/08/10/5802724.aspx 创建虚拟硬盘 1.关闭VM中正在运行的虚拟系统: 2.EDIT V ...
- _js day12
- 虚拟机克隆linux系统后需要做的网络设置
1.vim /etc/sysconfig/network-scripts/ifcfg-eth0删除HWMAC地址行,然后重新分配静态IP/掩码/网关/DNS 2.vim /etc/udev/rules ...
- css伪类选择器详细解析及案例使用-----伪元素
伪元素:(css3中将所有伪元素前变成了两个冒号,即::first-letter.::first-line.::before.::after.::selection.目的是为了区分伪元素与伪类.对于I ...
- javascript 获取滚动条高度+常用js页面宽度与高度(转)
/******************** *获取窗口滚动条高度 ******************/ function getScrollTop() { var scrollTop=0; if(d ...
- mysql配置文件转载
#BEGIN CONFIG INFO#DESCR: 4GB RAM, 只使用InnoDB, ACID, 少量的连接, 队列负载大#TYPE: SYSTEM#END CONFIG INFO ## 此my ...
- table超过30个字段如何处理呢? bootstrap
样式: @media (max-width: 768px) { .table-supplier { width: 100%; height: 100%; margin-bottom: 12.75px; ...
- SimpleDateFormat的部分方法
1,语法格式:new SimpleDateFormat("yyyy-MM-dd HH:mm") parse:String-->Date format:Date-->St ...