新巴巴运动网 项目第二天
-
今天内容
-
永久解决Jdk1.7
-
导入所有Jar包
-
七个Tomcat (配置)
-
Spring+Mybatis
-
测试
-
整合Springmvc
-
测试
-
什么是Dubbo 原理 图
-
整合Dubbo
-
测试Dubbo
-
永久解决Jdk1.7
-
Maven的插件
<!-- jdk1.7 --> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.2</version> <configuration> <source>1.7</source> <target>1.7</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build> |
-
导入所有Jar包
-
父工程
-
Spring 4.1.3
Mybatis 3.2.7
Springmvc 4.1.3
<!-- 设置统一控制版本 --> <properties> <java-version>1.7</java-version> <junit-version>4.12</junit-version> <spring.version>4.1.3.RELEASE</spring.version> <jackson.version>2.4.2</jackson.version> <mysql-connector-java-version>5.1.8</mysql-connector-java-version> <org.mybatis-version>3.2.7</org.mybatis-version> <org.mybatis-spring-version>1.2.2</org.mybatis-spring-version> <opensymphony-version>2.4.2</opensymphony-version> <freemarker-version>2.3.18</freemarker-version> <druid.version>1.0.9</druid.version> <commons-collections-version>1.0</commons-collections-version> <commons-fileupload-version>1.2.2</commons-fileupload-version> <org.apache.commons-version>3.1</org.apache.commons-version> <commons-codec-version>1.6</commons-codec-version> <dom4j-version>1.6.1</dom4j-version> <javax.servlet-version>1.2</javax.servlet-version> <aspectjweaver-version>1.6.6</aspectjweaver-version> <slf4j-log4j12-version>1.6.6</slf4j-log4j12-version> <log4j-version>1.2.16</log4j-version> <javax.servlet-jsp-version>2.0</javax.servlet-jsp-version> <cglib-version>2.2.2</cglib-version> <slf4j-api-version>1.6.6</slf4j-api-version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <!-- 依赖管理 版本号 --> <!-- 设置统一依赖管理、不强行依赖 --> <dependencyManagement> <dependencies> <!-- with junit4.8.2 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit-version}</version> <type>jar</type> </dependency> <!-- Spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</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-aspects</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</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-jms</artifactId> <version>${spring.version}</version> </dependency> <!-- Jackson Json处理工具包 --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>${jackson.version}</version> </dependency> <!--freemarker --> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>2.3.18</version> </dependency> <!-- with mybatis-spring --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${org.mybatis-version}</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>${org.mybatis-spring-version}</version> </dependency> <!-- jdbc driver --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql-connector-java-version}</version> </dependency> <!-- 连接池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>${druid.version}</version> </dependency> <!-- apache commons jar --> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>${commons-collections-version}</version> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>${commons-fileupload-version}</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>${org.apache.commons-version}</version> </dependency> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>${commons-codec-version}</version> </dependency> <!-- analyze xml use dom4j --> <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> <version>${dom4j-version}</version> </dependency> <!-- jstl标签 --> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.6.6</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.6.6</version> </dependency> <dependency> <groupId>javax.activation</groupId> <artifactId>activation</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>${cglib-version}</version> </dependency> <dependency> <groupId>net.fckeditor</groupId> <artifactId>java-core</artifactId> <version>2.6</version> </dependency> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20131018</version> </dependency> <!--page --> <dependency> <groupId>com.babasport</groupId> <artifactId>page</artifactId> <version>1.0</version> </dependency> <!-- solrJ --> <dependency> <groupId>org.apache.solr</groupId> <artifactId>solr-solrj</artifactId> <version>4.10.3</version> </dependency> <!-- jedis Java接口 --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.6.2</version> <type>jar</type> </dependency> <!-- FastDFS client --> <dependency> <groupId>fastdfs_client</groupId> <artifactId>fastdfs_client</artifactId> <version>1.20</version> </dependency> <dependency> <groupId>org.jboss.netty</groupId> <artifactId>netty</artifactId> <version>3.2.5.Final</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.5.3</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.1.41</version> </dependency> <!-- Zookeeper 用于分布式服务管理 --> <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> <version>0.1</version> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.6</version> </dependency> <!-- Zookeeper 用于分布式服务管理 end --> <!-- Active MQ 开始 --> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-all</artifactId> <version>5.8.0</version> </dependency> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-pool</artifactId> <version>5.8.0</version> </dependency> <!-- Active MQ 结束 --> </dependencies> </dependencyManagement> <dependencies> <!-- Tomcat7 servlet-api --> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-jsp-api</artifactId> <version>7.0.47</version> <scope>provided</scope> </dependency> </dependencies> |
-
babasport-common
<!-- 依赖管理之后台 --> <dependencies> <!-- with junit4.12 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> <!-- Spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jms</artifactId> </dependency> <!-- Jackson Json处理工具包 --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency> <!--freemarker --> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> </dependency> <!-- with mybatis-spring --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> </dependency> <!-- jdbc driver --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!-- 连接池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> </dependency> <!-- apache commons jar --> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> </dependency> <!-- analyze xml use dom4j --> <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> </dependency> <!-- jstl标签 --> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> <dependency> <groupId>javax.activation</groupId> <artifactId>activation</artifactId> </dependency> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> </dependency> <dependency> <groupId>net.fckeditor</groupId> <artifactId>java-core</artifactId> </dependency> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> </dependency> <!--page --> <dependency> <groupId>com.babasport</groupId> <artifactId>page</artifactId> </dependency> <!-- solrJ --> <dependency> <groupId>org.apache.solr</groupId> <artifactId>solr-solrj</artifactId> </dependency> <!-- jedis Java接口 --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> </dependency> <!-- FastDFS client --> <dependency> <groupId>fastdfs_client</groupId> <artifactId>fastdfs_client</artifactId> </dependency> <dependency> <groupId>org.jboss.netty</groupId> <artifactId>netty</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <exclusions> <exclusion> <artifactId>spring</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> </dependency> <!-- Zookeeper 用于分布式服务管理 --> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> </dependency> <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> </dependency> <!-- Zookeeper 用于分布式服务管理 end --> <!-- Active MQ 开始 --> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-all</artifactId> </dependency> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-pool</artifactId> </dependency> <!-- Active MQ 结束 --> </dependencies> |
-
配置七个Tomcat
项目名(无项目名)
www.babasport.com:80
-
整合Spring+Mybatis
Spring + Mybatis
整合思路
-
web.xml配置Spring监听器 读取上下文 配置上下文的路径
-
classpath:application-context.xml 事务 数据源 Mybatis的工厂 Mybatis Mapper扫描 基本包 jdbc.properties 读取properties Mybatis核心配置文件 mybatis-config.xml
sqlMapConfig.xml
-
分开
-
web.xml
配置Spring的监听器 上下文
-
在classpath application-context.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:task="http://www.springframework.org/schema/task" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
</beans> |
导入文件夹config中的所有xml文件
-
数据源 Druid
-
事务管理
-
扫描
-
配置mybatis
-
配置读jdbc.properties类
-
jdbc.properties
driverClassName=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/babasport22?characterEncoding=UTF-8 username=root password=root |
-
mybaits-config.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> |
-
测试 (注解式测试类)
-
数据库
-
-
表
-
JavaBean
-
Dao接口
-
Mapper
<?xml version= "1.0" encoding ="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
-
测试类
-
整合Springmvc
前端控制器
处理器映射器
处理器适配器
视图解释器
在babasport-console项目中配置如下内容
-
web.xml配置前端控制器
-
springmvc-console.xml
处理器映射器
处理器适配器
视图解释器
扫描
-
测试Springmvc
-
测试的页面
-
-
测试类
-
测试事务
-
Service实现类 不添加事务、手动抛异常
-
结论:此时仍然能保存数据到数据库
-
Service实现类 添加事务、手动抛异常
结论:此时不能保存数据到数据库
-
Dubbo介绍
阿里巴巴研究院
http://dubbo.io
-
原理
注册中心:软件 zookeeper redis 官方推荐zookeeper (动物园管理员)
Hadoop 就是zookeeper
Ip:端口号/接口
-
注册中心的搭建
Zookeeper(单机版)
第一步:上传
第二步:解压
第三步:在zookeeper-3.4.6文件夹中创建data、logs二个文件夹
第四步:配置zoo.cfg
第五步:启动
查看状态
-
搭建Dubbo服务提供方
-
搭建Dubbo的服务消费方
-
将上面服务消费方的TestService接口注入Controller中使用
-
注意事项
使用Dubbo框架、服务提供方与服务消费方之传递的参数必须实现序列化接口