CKG1156-Java Spring 技术栈构建前后台团购网站

来源:互联网 发布:发票作废 上传数据 编辑:程序博客网 时间:2024/06/08 19:00

CKG1156-Java Spring 技术栈构建前后台团购网站

学习要趁早,点滴记录,学习就是进步!

随笔背景:在很多时候,很多入门不久的朋友都会问我:我是从其他语言转到程序开发的,有没有一些基础性的资料给我们学习学习呢,你的框架感觉一下太大了,希望有个循序渐进的教程或者视频来学习就好了。对于学习有困难不知道如何提升自己可以加扣:1225462853进行交流得到帮助,获取学习资料.

CKG1156-Java Spring 技术栈构建前后台团购网站

下载地址:http://pan.baidu.com/s/1jI05TPW





这里是把 DispatcherServlet 命名为springMVC,并且让它在 Web 项目一启动就加载。接下来我们需要在/WebContent/WEB-INF/目录下创建一个springMVC-servlet.xml的Spring配置文件。Spring官方文档上推荐的默认的文件名是[servlet-name]-servlet.xml文件,这里 servlet-name 叫 springMVC ,因此,我新建了一个springMVC-servlet.xml。

<?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:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="  http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-4.2.xsd  http://www.springframework.org/schema/util  http://www.springframework.org/schema/util/spring-util-4.2.xsd  http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context-4.2.xsd  http://www.springframework.org/schema/mvc  http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd"><!-- 使用默认的注解映射 --><mvc:annotation-driven /><mvc:resources location="/" mapping="/index.html" /><!-- 自动扫描controller包中的控制器 --><context:component-scan base-package="cn.mayongfa.api.controller" /><context:component-scan base-package="cn.mayongfa.controller" /><!-- 上传文件拦截,设置最大上传文件大小 30M=30*1024*1024(B)=31457280 bytes --><bean id="multipartResolver"    class="org.springframework.web.multipart.commons.CommonsMultipartResolver">    <property name="maxUploadSize" value="31457280" /></bean>
在web.xml文件中定义的contextConfigLocation,指定要装入的 Spring 配置文件,一般文件都命名为applicationContext.xml,这个文件中我们可以进行扫描类包、读取配置文件、数据源管理、AOP配置、缓存以及消息队列等配置,所以,接下来就新建applicationContext.xml文件。

<?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:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop" 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/tx   http://www.springframework.org/schema/tx/spring-tx.xsd   http://www.springframework.org/schema/aop   http://www.springframework.org/schema/aop/spring-aop.xsd"><!-- 将多个配置文件读取到容器中,交给Spring管理 --><bean id="propertyConfigurer"    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">    <property name="locations">        <list>            <value>classpath:global.properties</value>            <value>classpath:jdbc.properties</value>        </list>    </property></bean><!-- 扫描类包,将标注Spring注解的类自动转化Bean,同时完成Bean的注入 --><context:component-scan base-package="cn.mayongfa.common" /><context:component-scan base-package="cn.mayongfa.service" /><context:component-scan base-package="cn.mayongfa.dao" /><!--master 配置数据源 --><bean id="masterDataSource" class="com.alibaba.druid.pool.DruidDataSource"    init-method="init" destroy-method="close">    <property name="driverClassName">        <value>${master.jdbc.driverClassName}</value>    </property>    <property name="url">        <value>${master.jdbc.url}</value>    </property>    <property name="username">        <value>${master.jdbc.username}</value>    </property>    <property name="password">        <value>${master.jdbc.password}</value>    </property>    ...</bean><!--slave 配置数据源 --><bean id="slaveDataSource" class="com.alibaba.druid.pool.DruidDataSource"    init-method="init" destroy-method="close">                ...</bean><bean id="dataSource" class="cn.mayongfa.service.imp.DynamicDataSource">    <property name="targetDataSources">        <map>            <entry key="slave" value-ref="slaveDataSource" />        </map>    </property>    <property name="defaultTargetDataSource" ref="masterDataSource" /></bean><!-- 配置Jdbc模板 --><bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">    <property name="dataSource" ref="dataSource"></property></bean><!-- 配置事务管理器 -->...<!-- 通过AOP配置提供事务增强,让service包下所有Bean的所有方法拥有事务 -->...



原创粉丝点击