当前位置:   article > 正文

springMVC+mybatis+dubbo实现SOA架构 以及数据查询_使用springboot+springmvc+dubbo+mybatis搭建微服务应用,实现根据id

使用springboot+springmvc+dubbo+mybatis搭建微服务应用,实现根据id查询订单功能

1:下载zookeeper ,稳定版3.4.8,最新版3.5.1,解压后,进入到conf目录,复制一份zoo_sample.conf,改名为zoo.conf,用无格式编辑器(比如sublime text,notepad等)打开,修改dataDir=/tmp/zookeeper为你的动物园管理员数据存放路径,比如笔者的为D:/软件/ zookeeperData /动物园管理员,修改为dataDir=D:/software/zookeeperData/zookeeper,保存即可,如果要配置ZK集群,还需要其他配置,暂时不说集群这一块,后面涉及到了再说。

zookeeper国内下载镜像地址:http ://mirrors.hust.edu.cn/apache/zookeeper/     bin /找到启动服务点击运行成功之后



2:下载JDK,maven安装配置这基础的东西就不说了找文档看看就会 

3:dubbo-admin.war

这个战争包是阿里达博团队开发的一个可视化操作达博的后台管理服务,可是查看机器,提供者,消费者,以及手动配置负载权重等。将次包下载后,放在tomcat的的的webapps目录下,如果你的tomcat的和动物园管理员不是同一台服务器,需要修改战争包下的配置文件,将地址指向的动物园管理员的服务地址,端口是动物园管理员的端口,默认2181。



整体结构简单的分了一下,如下图所示:

1:新建项目


2;接着新建选中当前项目在当前项目下面接着新建模块soa-api


2.1:新建接口


的pom.xml
  1. <?xml version =“1.0”?>
  2. <project xsischemaLocation =“http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0xsd
  3. xmlns =”http://maven.apache.org/POM/4.0.0“xmlns:xsi =”http://www.w3.org/2001/XMLSchema-instance“>
  4. <modelVersion> 4.0.0 < / modelVersion>
  5. <parent>
  6. <groupId> cn.dubbo </ groupId>
  7. <artifactId> soa-dubbo </ artifactId>
  8. <version> 0.0.1-SNAPSHOT </ version>
  9. </ parent>
  10. <groupId> cn.dubbo.api </ groupId>
  11. <artifactId> dubbo-api </ artifactId>
  12. <name> dubbo-api </ name>
  13. <url> http://maven.apache.org </ url>
  14. <properties>
  15. <project.build.sourceEncoding> UTF-8 </project.build.sourceEncoding>
  16. </ properties>
  17. <dependencies>
  18. <dependency>
  19. <groupId> cn.dubbo.pojo </ groupId>
  20. <artifactId> dubbo-pojo </ artifactId>
  21. <version> 0.0.1- SNAPSHOT </ version>
  22. </ dependency>
  23. <dependency>
  24. <groupId> junit </ groupId>
  25. <artifactId> junit </ artifactId>
  26. <version> 3.8.1 </ version>
  27. <scope> test </ scope>
  28. </ dependency>
  29. </ dependencies>
  30. </ project>

继续新建pojo实体类模块核心工具类模块api-imp实现模块和上面新建api接口过程是一样的我就不截图了直接上代码

pojo模块


pom.xml

  1. <?xml version =“1.0”?>
  2. <project xsischemaLocation =“http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0xsd
  3. xmlns =”http://maven.apache.org/POM/4.0.0“xmlns:xsi =”http://www.w3.org/2001/XMLSchema-instance“>
  4. <modelVersion> 4.0.0 < / modelVersion>
  5. <parent>
  6. <groupId> cn.dubbo </ groupId>
  7. <artifactId> soa-dubbo </ artifactId>
  8. <version> 0.0.1-SNAPSHOT </ version>
  9. </ parent>
  10. <groupId> cn.dubbo.pojo </ groupId>
  11. <artifactId> dubbo-pojo </ artifactId>
  12. <name> dubbo-pojo </ name>
  13. <url> http://maven.apache.org </ url>
  14. <properties>
  15. <project.build.sourceEncoding> UTF-8 </project.build.sourceEncoding>
  16. </ properties>
  17. <dependencies>
  18. <dependency>
  19. <groupId> junit </ groupId>
  20. <artifactId> junit </ artifactId>
  21. <version> 3.8.1 </ version>
  22. <scope> </ scope>
  23. </ dependency>
  24. </ dependencies>
  25. </ project>

core模块


pom.xml

  1. <?xml version =“1.0”?>
  2. <project xsischemaLocation =“http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0xsd
  3. xmlns =”http://maven.apache.org/POM/4.0.0“xmlns:xsi =”http://www.w3.org/2001/XMLSchema-instance“>
  4. <modelVersion> 4.0.0 < / modelVersion>
  5. <parent>
  6. <groupId> cn.dubbo </ groupId>
  7. <artifactId> soa-dubbo </ artifactId>
  8. <version> 0.0.1-SNAPSHOT </ version>
  9. </ parent>
  10. <groupId> cn.dubbo.core </ groupId>
  11. <artifactId> dubbo-core </ artifactId>
  12. <name> dubbo-core </ name>
  13. <url> http://maven.apache.org </ url>
  14. <properties>
  15. <project.build.sourceEncoding> UTF-8 </project.build.sourceEncoding>
  16. <spring.version> 4.1.4.RELEASE </spring.version>
  17. <spring-ck.version> 3.0.5.RELEASE </spring-ck.version>
  18. <jackson。版本> 2.5.0 </jackson.version>
  19. </ properties>
  20. <dependencies>
  21. <dependency>
  22. <groupId> junit </ groupId>
  23. <artifactId> junit </ artifactId>
  24. <version> 3.8.1 </ version>
  25. <scope>测试</ scope>
  26. </ dependency>
  27. <! - spring - >
  28. <dependency>
  29. <groupId> org.springframework </ groupId>
  30. <artifactId> spring-web </ artifactId>
  31. <version> $ { pring-ck.version} </ version>
  32. </ dependency>
  33. <dependency>
  34. <groupId> org.springframework </ groupId>
  35. <artifactId> spring-webmvc </ artifactId>
  36. <version> $ {spring-ck.version}版本>
  37. </依赖性>
  38. <依赖性>
  39. <的groupId> org.springframework </的groupId>
  40. <artifactId的>弹簧OXM </ artifactId的>
  41. <版本> $ {弹簧ck.version} </版本>
  42. </依赖性>
  43. <依赖性>
  44. <groupId> org.springframework </ groupId>
  45. <artifactId> spring-orm </ artifactId>
  46. <version> $ {spring-ck.version} </ version>
  47. </ dependency>
  48. <dependency>
  49. <groupId> org.springframework < / groupId>
  50. <artifactId> spring-jdbc </ artifactId>
  51. <version> $ {spring.version} </ version>
  52. </ dependency>
  53. <dependency>
  54. <groupId> org.springframework </ groupId>
  55. <artifactId> spring-test < /的artifactId>
  56. <版本> $ {spring.version} </版本>
  57. <范围>测试</范围>
  58. </依赖性>
  59. <依赖性>
  60. <的groupId> com.alibaba </的groupId>
  61. <artifactId的>多宝</ artifactId的>
  62. <版本> 2.5.3 </ version>
  63. <排除>
  64. <排除>
  65. <artifactId> spring </ artifactId>
  66. <groupId> org.springframework </ groupId>
  67. </排除>
  68. </排除>
  69. </ depe ndency>
  70. <dependency>
  71. <groupId> org.apache.zookeeper </ groupId>
  72. <artifactId> zookeeper </ artifactId>
  73. <version> 3.4.6 </ version>
  74. </ dependency>
  75. <dependency>
  76. <groupId> com.netflix.curator </的groupId>
  77. <artifactId的>馆长的框架</ artifactId的>
  78. <版本> 1.1.10 </版本>
  79. </依赖性>
  80. <依赖性>
  81. <的groupId> com.101tec </的groupId>
  82. <artifactId的> zkclient </ artifactId的>
  83. <版本> 0.6 </ version>
  84. </ dependency>
  85. <dependency>
  86. <groupId> javax.servlet </ groupId>
  87. <artifactId> jstl </ artifactId>
  88. <version> 1.2 </ version>
  89. </ dependency>
  90. <! - mybatis - >
  91. <dependency>
  92. <groupId> org.mybatis </ groupId>
  93. <artifactId> mybatis </ artifactId>
  94. <version> 3.2.8 </ version>
  95. </ dependency>
  96. <! - mybatis spring插件 - >
  97. <dependency >
  98. <groupId> org.mybatis </ groupId>
  99. <artifactId> mybatis-spring </ artifactId>
  100. <version> 1.2.2 </ version>
  101. </ dependency>
  102. <! - mysql连接 - >
  103. <dependency>
  104. <groupId> mysql </ groupId>
  105. <artifactId> mysql-connector-java </ artifactId>
  106. <version> 5.1.34 </ version>
  107. </ dependency>
  108. <! - 数据源 - >
  109. <dependency>
  110. <groupId> com.alibaba < / groupId>
  111. <arti factId> druid </ artifactId>
  112. <version> 1.0.12 </ version>
  113. </ dependency>
  114. <dependency>
  115. <groupId> org.aspectj </ groupId>
  116. <artifactId> aspectjweaver </ artifactId>
  117. <version>版本>
  118. </ dependency>
  119. <! - json - >
  120. <dependency>
  121. <groupId> org.codehaus.jackson </ groupId>
  122. <artifactId> jackson-mapper-asl </ artifactId>
  123. <version> 1.9.13 </ version >
  124. </ dependency>
  125. < dependency> <dependencyId>
  126. com.alibaba </ groupId>
  127. <artifactId> fastjson </ artifactId>
  128. <version> 1.2.3 </ version>
  129. </ dependency>
  130. <dependency>
  131. <groupId> com.fasterxml。 jackson.core </ groupId>
  132. <artifactId> jackson-annotations </ artifactId>
  133. <version> $ {jackson.version} </ version>
  134. </ dependency>
  135. <dependency>
  136. <groupId> com.fasterxml.jackson.core </ groupId >
  137. <artifactId> jackson-core </ artifactId>
  138. <version> $ {jackson.version} </ version>
  139. </ dependency>
  140. <dependency>
  141. <groupId> com.fasterxml.jackson.core </ groupId>
  142. <artifactId> jackson- databind </ artifactId>
  143. <version> $ {jackson.version} </ version>
  144. </ dependency>
  145. <! - 文件上传 - >
  146. <dependency>
  147. <groupId> commons-io </ groupId>
  148. <artifactId> commons-i o </ artifactId>
  149. <version> 2.4 </ version>
  150. </ dependency>
  151. <dependency>
  152. <groupId> commons-fileupload </ groupId>
  153. <artifactId> commons-fileupload </ artifactId>
  154. <version> 1.2.2 </ version>
  155. </ dependency>
  156. <! - servlet - >
  157. <dependency>
  158. <groupId> javax.servlet </ groupId>
  159. <artifactId> javax.servlet-api </ artifactId>
  160. <version> 3.0.1 </ version>
  161. </ dependency >
  162. </ dependencies>
  163. </ project>

api-imp模块


UserserviceImp

  1. 包org.dubbo.api.imp;
  2. import org.dubbo.api.dao.UserMapper;
  3. import org.dubbo.api.service.UserService;
  4. import org.dubbo.pojo.User;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Service;
  7. @Service(“userService”)
  8. public class UserServiceImp实现UserService {
  9. @Autowired
  10. UserMapper userMapper;
  11. public User findById(int id){
  12. User us = userMapper.findById(1);
  13. 回归我们
  14. }
  15. }
DubboMain

  1. package org.dubbo.api.main;
  2. import java.io.IOException;
  3. import org.springframework.context.support.ClassPathXmlApplicationContext;
  4. public class DubboMain {
  5. public static void main(String [] args)throws IOException {
  6. ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext
  7. new String [] {“dubbo.xml”});
  8. context.start();
  9. System.in.read(); //按任意键退出
  10. // Main.main(args);
  11. }
  12. }

log4j的

  1. ### set log levels ###  
  2. log4j.rootLogger = INFO,C,D,E   
  3.   
  4. ### console ###  
  5. log4j.appender.C = org.apache.log4j.ConsoleAppender  
  6. log4j.appender.C.Target = System。 out  
  7. log4j.appender.C.layout = org.apache.log4j.PatternLayout  
  8. log4j.appender.C.layout.ConversionPattern = [%p] [%-d {yyyy-MM-dd HH:mm:ss}]%C。 %M(%L)| %m%n  
  9.   
  10. ### log file ###  
  11. log4j.appender.D = org.apache.log4j.DailyRollingFileAppender  
  12. log4j.appender.D.File = ../logs/ServerManager-Info.log  
  13. log4j.appender.D.Append = true  
  14. log4j.appender.D.Threshold = INFO   
  15. log4j.appender.D.layout = org.apache.log4j.PatternLayout  
  16. log4j.appender.D.layout.ConversionPattern = [%p] [%-d {yyyy-MM-dd HH:mm:ss}]%C.%M(%L)| %m%n  
  17.   
  18. ### exception ###  
  19. log4j.appender.E = org.apache.log4j.DailyRollingFileAppender  
  20. log4j.appender.E.File = ../logs/ServerManager-Error.log  
  21. log4j.appender.E.Append = true  
  22. log4j.appender.E.Threshold = ERROR   
  23. log4j.appender.E.layout = org.apache.log4j.PatternLayout  
  24. log4j.appender.E.layout.ConversionPattern = [%p] [%-d {yyyy-MM-dd HH :mm:ss}]%C.%M(%L)| %米%正  

dubbo.xml

  1. <?xml version =“1.0”encoding =“UTF-8”?>
  2. <beans xmlns =“http://www.springframework.org/schema/beans”xmlns:xsi =“http://www.w3.org / 2001 / XMLSchema-instance
  3. xmlnsdubbo =”http://code.alibabatech.com/schema/dubbo“
  4. xsischemaLocation =”http://www.springframework.org/schema/beans       
  5.     http:// wwwspringframework.org/schema/beans/spring-beans.xsd       
  6.     http://code.alibabatech.com/schema/dubbo        
  7.     http://code.alibabatech.com/schema/dubbo/dubbo.xsd“>
  8. <! - 提供方法应用信息 - >
  9. <dubbo:application name =“dubbo_provider”/>
  10. <! - 使用zookeeper注册中心暴露服务地址 - >
  11. <dubbo:registry address =“127.0.0.1:2181” protocol =“zookeeper”/>
  12. <! - 用dubbo协议在20880端口暴露服务 - >
  13. <dubbo:protocol name =“dubbo”port =“20880”/>
  14. <! - 声明需要暴露的服务接口 - >
  15. <dubbo:service interface =“org.dubbo.api.service.UserService”ref =“userService”/>
  16. <bean id =“userService”class =“org.dubbo.api.imp.UserServiceImp”> </ bean>
  17. <import resource =“classpath *:applicationMybatis.xml”/>
  18. </ bea NS>

db

  1. driverClassName = com.mysql.jdbc.Driver
  2. url = jdbc:mysql:// localhost:3306 / wb ?? useUnicode = true&characterEncoding = UTF-8
  3. username = root
  4. password = 1234
  5. c3p0.pool.size.max = 20
  6. c3p0.pool。 size.min = 5
  7. c3p0.pool.size.ini = 3
  8. c3p0.pool.size.increment = 2

applicationMabatis

  1. <?xml version =“1.0”encoding =“UTF-8”?>
  2. <beans xmlns =“http://www.springframework.org/schema/beans”xmlns:mvc =“http://www.springframework.org / schema / mvc
  3. xmlnsxsi =”http://www.w3.org/2001/XMLSchema-instance“xmlns:aop =”http://www.springframework.org/schema/aop“
  4. xmlnstx = http://www.springframework.org/schema/txxmlnscontext =”http://www.springframework.org/schema/context“
  5. xsischemaLocation =
  6.         http://www.springframework.org/schema/ beans
  7.         http://www.springframework.org/schema/beans/spring-beans.xsd
  8.         http://www.springframework.org/schema/mvc
  9.         http://www.springframework.org/schema/mvc/spring-mvc .xsd
  10.         http://www.springframework.org/schema/context
  11.         http://www.springframework.org/schema/context/spring-context.xsd
  12. http://www.springframework.org/schema/tx
  13.      http:/ /www.springframework.org/schema/tx/spring-tx.xsd
  14.      http://www.springframework.org/schema/aop
  15.      http://www.springframework.org/schema/aop/spring-aop.xsd“>
  16. <! - 加载配置文件 - >
  17. <context:property-placeholder location =“classpath *:db.properties” />
  18. <! - 数据源,使用dbcp - >
  19. <bean id =“dataSource”class =“com.alibaba.druid.pool.DruidDataSource”destroy-method =“close”>
  20. <property name =“driverClassName” =“$ {driverClassName}”/>
  21. <property name =“url”value =“$ {url}”/>
  22. <property name =“username”value =“$ {username}”/>
  23. <property name =“password” value =“$ {password}”/>
  24. <! - <property name =“maxPoolSize”value =“$ {c3p0.pool.size.max}”/> <property name =“minPoolSize”value =“$ {c3p0 .pool.size.min}“ 
  25. /> <property name =”initialPoolSize“value =”$ {c3p0.pool.size.ini}“/> <property name =”acquireIncrement“ 
  26. value =”$ {c3p0.pool.size .increment}“/> - >
  27. </ bean>
  28. <! - sqlSessionFactory - >
  29. <bean id =”sqlSessionFactory“class =”org.mybatis.spring.SqlSessionFactoryBean“>
  30. <! - 加载mybatis的配置文件 - - >
  31. <属性名= “typeAliasesPackage”值= “org.dubbo.pojo”> </属性>
  32. <属性名= “mapperLocations”值= “类路径:组织/多宝/ API /刀/ * XML”/>
  33. < ! -数据源- >
  34. <属性名= “数据源” REF = “数据源”/>
  35. </>
  36. <! -映射器批量扫描 从映射器包中扫描出映射器接口,自动创建代理对象并且在弹簧容器中注册- >
  37. <! -自动扫描出来的映射器的豆的ID为映射器类名(首字母小写) - >
  38. <! - - 扫描多个包用,分开 - >
  39. <bean class =“org.mybatis.spring.mapper.MapperScannerConfigurer”>
  40. <property name =“basePackage”value =“org.dubbo.api.dao”/>
  41. <property name =“sqlSessionFactoryBeanName”value =“sqlSessionFactory”/>
  42. </ bean>
  43. <! - 事物管理器对于mybatis操作数据库事物控制,spring使用Jdbc的事物控制类 - >
  44. <bean id =“transactionManager”class =“org .springframework.jdbc.datasource.DataSourceTransactionManager“>
  45. <! - 数据源dataSource在applicationContext-dao.xml中配置了 - >
  46. <property name =”dataSource“ref =”dataSource“> </ property>
  47. </ bean>
  48. <! - 通知 - >
  49. <tx:advice id =“txAdvice”transaction-manager =“transactionManager”>
  50. <tx:attributes>
  51. <! - 传播行为 - >
  52. <tx:method name =“save *” =“REQUIRED”/>
  53. <tx:method name =“add *”propagation =“REQUIRED”/>
  54. <tx:method name =“ insert *“propagation =”REQUIRED“/>
  55. <tx:method name =”update *“propagation =”REQUIRED“/>
  56. <tx:method name =”delete *“propagation =”REQUIRED“/>
  57. <tx:method name = “找到*”传播= “支撑件”只读= “真”/>
  58. <TX:方法名= “*”传播= “支撑件”只读= “真”/>
  59. </ TX:属性>
  60. </ TX :advice>
  61. <! - aop - >
  62. <aop:config>
  63. <aop:advisor advice-ref =“txAdvice”pointcut =“execution(* org.dubbo.api.imp .. *。*(..)) “/>
  64. </ aop:config>
  65. </ beans>

好到这里该去试下dubbo和zoopeeker通不通了找到DubooMain类运行主方法控制台没报错说明已经成功


相应zoopeeper命令行也会有动荡  

下面开始整合springmvc + mybatis

找到新建的api-imp模块

新建dao  包


还有对应的xml你可以自动生成也可以手动写我这里手动写了UserMapper.xml

  1. <?xml version =“1.0”encoding =“UTF-8”?>
  2. <!DOCTYPE mapper
  3.  PUBLIC“ - // mybatis.org//DTD Mapper 3.0 // EN”
  4. “http://mybatis.org/dtd/mybatis -3-mapper.dtd“>
  5. <mapper namespace =”org.dubbo.api.dao.UserMapper“>
  6. <resultMap id =”user“type =”org.dubbo.pojo.User“>
  7. <id column =”userid“ property =“userid”/>
  8. <result column =“name”property =“name”/>
  9. </ resultMap>
  10. <select id =“findById”parameterType =“int”resultType =“user”>
  11. select * from user where userid =
  12. #{id}
  13. </ select>
  14. </ mapper>

添加完成之后在运行一下刚刚的main方法看报不报错不报错那就问题不大了继续往下

新建一个模块控制层soa-action

\





  这里有报错不要管它不影响使用编译的问题

UserAction

  1. 包org.dubbo.action;
  2. import javax.servlet.http.HttpServletRequest;
  3. import org.dubbo.api.service.UserService;
  4. import org.dubbo.pojo.User;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.context.annotation.Scope;
  7. import org.springframework.stereotype.Controller;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RequestMethod;
  10. @Controller
  11. @Scope(“prototype”)@ RequestMapping(
  12. value =“/ wx”)
  13. public class UserAction {
  14. @Autowired
  15. public UserService userService;
  16. @RequestMapping(value =“/ listUser”,method = RequestMethod.GET)
  17. public void listUser(HttpServletRequest request){
  18. User u = userService.findById(1);
  19. 通信System.err.println(u.getName());
  20. }
  21. }

dubbo_action

  1. <?xml version =“1.0”encoding =“UTF-8”?>
  2. <beans xmlns =“http://www.springframework.org/schema/beans”xmlns:xsi =“http://www.w3.org / 2001 / XMLSchema-instance
  3. xmlnsdubbo =”http://code.alibabatech.com/schema/dubbo“
  4. xsischemaLocation =”http://www.springframework.org/schema/beans
  5.           http:// wwwspringframework.org/schema/beans/spring-beans.xsd
  6.                   http://code.alibabatech.com/schema/dubbo
  7.                           http://code.alibabatech.com/schema/dubbo/dubbo.xsd“>
  8. <! - 消费方法应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 - >
  9. <! - <dubbo:application name =“consumer-of-helloworld-app”/> - >
  10. <!使用组播广播注册中心暴露发现服务地址 - >
  11. <! - <dubbo:registry address =“multicast://224.5.6.7:1234”/> - >
  12. <! - 公共信息,也可以用dubbo。属性配置 - >
  13. <dubbo:application name =“annotation-consumer”/>
  14. <dubbo:registry address =“127.0.0.1:2181”protocol =“zookeeper”/>
  15. <! - 扫描注解包路径,多个包用逗号分隔,不填pacakge表示扫描当前的ApplicationContext 中所有的类 - >
  16. <! - <dubbo:annotation package =“com.alibaba.dubbo.demo”/> - >
  17. <! - 生成远程服务代理,可以和本地bean一样使用demoService - >
  18. <dubbo:reference id =“userService”interface =“org.dubbo.api.service.UserService”/>
  19. <! - 声明需要引用的服务接口 - >
  20. </ beans>

log4j直接复制上面api-imp接口实现的

用SpringMVC

  1. <?xml version =“1.0”encoding =“UTF-8”?>
  2. <beans xmlns =“http://www.springframework.org/schema/beans”xmlns:xsi =“http://www.w3.org / 2001 / XMLSchema-instance
  3. xmlnsmvc =”http://www.springframework.org/schema/mvc“xmlns:context =”http://www.springframework.org/schema/context“
  4. xmlnsaop = http://www.springframework.org/schema/aopxmlnstx =”http://www.springframework.org/schema/tx“
  5. xsischemaLocation =”http://www.springframework.org/schema/豆 
  6.             http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
  7.             http://www.springframework.org/schema/mvc 
  8.             http://www.springframework.org/schema/mvc/spring -mvc-3.0.xsd 
  9.             http://www.springframework.org/schema/context 
  10.             http://www.springframework.org/schema/context/spring-context-3.0.xsd 
  11.             http://www.springframework.org/ schema / aop 
  12.             http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
  13.             http://www.springframework.org/schema/tx 
  14.             http://www.springframework.org/schema/tx /spring-tx-3.0.xsd“>
  15. <context:annotation-config />
  16. <context:component-scan base-package =”org.d ubbo.action“>
  17. <context:include-filter type =”annotation“expression =”org.springframework.stereotype.Controller“/>
  18. </ context:component-scan>
  19. <bean class =”org.springframework.web.servlet。 mvc.annotation.AnnotationMethodHandlerAdapter“/>
  20. <bean class =”org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping“/>
  21. <! - 静态资源的访问 - >
  22. <! - 视图分解器 - >
  23. <bean id =“viewResolver”class =“org.springframework.web.servlet.view.InternalResourceViewResolver”>
  24. <property name =“prefix”value =“/”/>
  25. <property name =“suffix”value =“。jsp” />
  26. </ bean>
  27. <! - 国际化的消息资源文件(本系统中主要用于显示/错误消息定制) - >
  28. <bean id =“messageSource”class =“org.springframework.context.support。 ReloadableResourceBundleMessageSource “>
  29. <属性名=”基本名称“>
  30. <列表>
  31. < -在网络环境中一定要定位到classpath中否则默认到当前的Web应用下找- >!
  32. <>类路径:/邮件</>
  33. < / list>
  34. </ property>
  35. <property name =“useCodeAsDefaultMessage”value = “false”/>
  36. <property name =“defaultEncoding”value =“UTF-8”/>
  37. <property name =“cacheSeconds”value =“60”/>
  38. </ bean>
  39. <! - 避免IE在ajax请求时,返回json发现下载 - >
  40. <bean id =“jacksonMessageConverter”class =“org.springframework.http.converter.json.MappingJacksonHttpMessageConverter”>
  41. <property name =“supportedMediaTypes”>
  42. <list>
  43. <value> text / html; charset = UTF-8 </ value>
  44. </ list>
  45. </ property>
  46. </ bean>
  47. <! - 上传文件的解析器 - >
  48. <bean id =“multipartResolver”class =“org.springframework.web.multipart.commons .CommonsMultipartResolver “>
  49. <属性名=” defaultEncoding”值= “UTF-8”/>
  50. <属性名= “maxUploadSize”值= “10485760000”/>
  51. <属性名= “maxInMemorySize”值= “40960”/>
  52. </ bean>
  53. <import resource =“classpath:dubbo_action.xml”/>
  54. </ beans>

POM

  1. <?xml version =“1.0”?>
  2. <project xsischemaLocation =“http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0xsd
  3. xmlns =”http://maven.apache.org/POM/4.0.0“xmlns:xsi =”http://www.w3.org/2001/XMLSchema-instance“>
  4. <modelVersion> 4.0.0 < / modelVersion>
  5. <parent>
  6. <groupId> cn.dubbo </ groupId>
  7. <artifactId> soa-dubbo </ artifactId>
  8. <version> 0.0.1-SNAPSHOT </ version>
  9. </ parent>
  10. <artifactId> dubbo-action < artifactId>
  11. <packaging> war </
  12. package > <name> dubbo-action Maven Webapp </ name>
  13. <url> http://maven.apache.org </ url>
  14. <dependencies>
  15. <dependency>
  16. <groupId> cn.dubbo .pojo </ groupId>
  17. <artifactId> dubbo-pojo </ artifactId>
  18. <version> 0.0.1-SNAPSHOT </ version>
  19. </ dependency>
  20. <dependency>
  21. <groupId> cn.dubbo.api </ groupId>
  22. <artifactId> dubbo-api </ artifactId>
  23. <version> 0.0.1-SNAPSHOT </ version>
  24. </ dependency>
  25. <dependency>
  26. <groupId> cn.dubbo.core </ groupId>
  27. <artifactId> dubbo-core </ artifactId>
  28. <version > 0.0.1-SNAPSHOT </ version>
  29. </ dependency>
  30. <dependency>
  31. <groupId> junit </ groupId>
  32. <artifactId> junit </ artifactId>
  33. <version> 4。12 </ version>
  34. <scope> test </ scope>
  35. </ dependency>
  36. </ dependencies>
  37. <build>
  38. <finalName> dubbo-action </ finalName>
  39. </ build>
  40. </ project>
web.xml中

  1. xmlns =“1.0”encoding =“UTF-8”?< http://www.w3.org/2001/XMLSchema-instance“xsi:schemaLocation
  2. =”http://java.sun.com/xml/ns/javaee
  3. http://java.sun.com/xml/ns/的JavaEE /网络app_2_5.xsd“>
  4. <servlet>
  5. <servlet的名称>用SpringMVC </ servlet的名称>
  6. <servlet的类> org.springframework.web.servlet.DispatcherServlet </ servlet的类>
  7. <INIT-PARAM>
  8. < param-name> contextConfigLocation </ param-name>
  9. <param-value> classpath *:springmvc.xml </ param-value>
  10. </ init-param>
  11. <load-on-startup> 1 </ load-on-startup>
  12. </ servlet>
  13. <servlet-mapping>
  14. <servlet-name> springmvc </ servlet-name>
  15. <url-pattern> * 。do < / url-pattern>
  16. </ servlet-mapping>
  17. <filter>
  18. <filter-name> SpringEncodingFilter </ filter-name>
  19. <filter-class> org.springframework.web.filter.CharacterEncodingFilter </ filter-class>
  20. <init-param>
  21. <param-name> encoding </ param-name>
  22. <param-value> UTF- 8 </ param-value>
  23. </ init-param>
  24. <init-param>
  25. <param-name> forceEncoding </ param-name>
  26. <param-value> true </ param-value>
  27. </ ini t-param>
  28. </ filter>
  29. <filter-mapping>
  30. <filter-name> SpringEncodingFilter </ filter-name>
  31. <url-pattern> / * </ url-pattern>
  32. </ filter-mapping>
  33. <welcome-file-list >
  34. <welcome-file> login.jsp </ welcome-file>
  35. </ welcome-file-list>
  36. </ web-app>


好到这里就完事了检查一下代码如果没有问题启动zoopeeker启动api-imp里面的main方法然后tomcat启动当前的这个web程序   打开浏览器请求这个地址然后返回去看IDE输出的数据

     

如果有打印说明基本配置已完成 


如果上述看的不是很明白这里有写好能运行的源代码 

http://download.csdn.net/download/wangbo54979/9934692



声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/166053?site
推荐阅读
相关标签
  

闽ICP备14008679号