当前位置: 首页 > news >正文

网站建设上线企业电子商务网站建设的重要性

网站建设上线,企业电子商务网站建设的重要性,建立免费空间网站,ui设计就业方向有哪些?1.Dubbo中的版本号 每个接口都应定义版本号,为后续不兼容升级提供可能。当一个接口有不同的实现,项目早期使用的一个实现类, 之后创建接口的新的实现类。区分不同的接口实现使用 version。 特别是项目需要把早期接口的实现全部换位新的实现类…

1.Dubbo中的版本号

每个接口都应定义版本号,为后续不兼容升级提供可能。当一个接口有不同的实现,项目早期使用的一个实现类, 之后创建接口的新的实现类。区分不同的接口实现使用 version。

特别是项目需要把早期接口的实现全部换位新的实现类,也需要使用 version。

可以用版本号从早期的接口实现过渡到新的接口实现,版本号不同的服务相互间不引用。

可以按照以下的步骤进行版本迁移:

  • 在低压力时间段,先升级一半提供者为新版本
  • 再将所有消费者升级为新版本
  • 然后将剩下的一半提供者升级为新版本

2.案例分析

最近两天一直都在学习Dubbo,说来说去,那开始依旧是三个工程(第一个是maven java工程、后两个是maven web工程)。 下面是这三个工程的架构。

2.1 第一个是maven java工程

这其中提供的是服务模型(实体Bean)、服务接口(对外提供的方法),这个工程不需要添加任何依赖。

package com.szh.dubbo.model;import java.io.Serializable;/****/
public class User implements Serializable {private Integer id;private String username;//getter and setter
}
package com.szh.dubbo.service;import com.szh.dubbo.model.User;/****/
public interface UserService {User queryUserById(Integer id,String username);}

2.2 第二个是maven web工程

这个代表的是服务提供者,其中包含对第一个maven java工程中服务接口方法的实现。但是我们这里为服务接口提供两个实现类,来体现对版本号version的使用。

package com.szh.dubbo.service.impl;import com.szh.dubbo.model.User;
import com.szh.dubbo.service.UserService;/****/
public class UserServiceImpl implements UserService {@Overridepublic User queryUserById(Integer id, String username) {User user=new User();user.setId(id);user.setUsername(username + "-1");return user;}
}
package com.szh.dubbo.service.impl;import com.szh.dubbo.model.User;
import com.szh.dubbo.service.UserService;/****/
public class UserServiceImpl2 implements UserService {@Overridepublic User queryUserById(Integer id, String username) {User user=new User();user.setId(id);user.setUsername(username + "-2");return user;}
}

然后是dubbo服务提供者的配置文件。这里仍然使用zookeeper注册中心,将服务接口的两个实现类加载到spring容器中,最后在web.xml中配置spring的监听器,同时读取dubbo配置文件。

<?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:dubbo="http://dubbo.apache.org/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd"><dubbo:application name="009-zk-userservice-multi-provider"/><dubbo:protocol name="dubbo" port="20880"/><dubbo:registry address="zookeeper://localhost:2181"/><dubbo:service interface="com.szh.dubbo.service.UserService" ref="userServiceImpl" version="1.0.0"/><dubbo:service interface="com.szh.dubbo.service.UserService" ref="userServiceImpl2" version="2.0.0"/><bean id="userServiceImpl" class="com.szh.dubbo.service.impl.UserServiceImpl"/><bean id="userServiceImpl2" class="com.szh.dubbo.service.impl.UserServiceImpl2"/></beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"version="4.0"><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:dubbo-userservice-multi-provider.xml</param-value></context-param></web-app>

pom文件中的相关依赖。

    <!-- Spring依赖 --><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.2.5.RELEASE</version></dependency><!-- SpringMVC依赖 --><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.2.5.RELEASE</version></dependency><!-- Dubbo依赖 --><dependency><groupId>com.alibaba</groupId><artifactId>dubbo</artifactId><version>2.6.2</version></dependency><!-- 接口工程依赖 --><dependency><groupId>com.szh.dubbo</groupId><artifactId>006-zk-interface</artifactId><version>1.0.0</version></dependency><!-- Zookeeper依赖 --><dependency><groupId>org.apache.curator</groupId><artifactId>curator-framework</artifactId><version>4.1.0</version></dependency>

2.3 第三个是maven web工程

这个代表的是服务消费者,其中包含一个控制层方法的实现,去响应之前的服务接口。

package com.szh.dubbo.controller;import com.szh.dubbo.model.User;
import com.szh.dubbo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;/****/
@Controller
public class UserController {@Autowiredprivate UserService userService1;@Autowiredprivate UserService userService2;@RequestMapping(value = "/userDetail")public String userDetail(Model model,Integer id,String username) {User user1=userService1.queryUserById(id,username);User user2=userService2.queryUserById(id,username);model.addAttribute("user1",user1);model.addAttribute("user2",user2);return "userDetail";}
}

然后是dubbo服务消费者的配置文件、Spring配置文件。

<?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:dubbo="http://dubbo.apache.org/schema/dubbo"xmlns:dubo="http://code.alibabatech.com/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"><dubbo:application name="010-zk-multi-consumer"/><dubo:registry address="zookeeper://localhost:2181"/><dubbo:reference id="userService1" interface="com.szh.dubbo.service.UserService" version="1.0.0"/><dubbo:reference id="userService2" interface="com.szh.dubbo.service.UserService" version="2.0.0"/></beans>
<?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:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd"><context:component-scan base-package="com.szh.dubbo.controller"/><mvc:annotation-driven/><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/"/><property name="suffix" value=".jsp"/></bean></beans>

最后是web.xml和控制层方法对应的jsp页面。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"version="4.0"><servlet><servlet-name>DispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml,classpath:dubbo-multi-consumer.xml</param-value></init-param></servlet><servlet-mapping><servlet-name>DispatcherServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping>
</web-app>
<%@ page contentType="text/html;charset=utf-8" language="java" %>
<html>
<head><title>$</title>
</head>
<body><h3>用户1的信息</h3><div>用户编号:${user1.id}</div><div>用户姓名:${user1.username}</div><hr/><h3>用户2的信息</h3><div>用户编号:${user2.id}</div><div>用户姓名:${user2.username}</div>
</body>
</html>

2.4 启动测试!!!

步骤在上一篇博文中已经说过了,链接:Dubbo——使用Zookeeper注册中心实现Dubbo_zookeeper中的dubbo-CSDN博客

下面是测试结果:

http://www.yayakq.cn/news/494785/

相关文章:

  • ps为什么做不了视频网站设计网站推荐平面
  • 亳州建设网站公司推广发帖网站怎么做
  • html5购物网站源码seo公司是什么
  • 软文发布门户网站怎么做一个微信公众号
  • php的网站怎么做百度网盟推广太恶心
  • 廊坊建设银行网站官网优化哪家专业
  • 南昌企业网站建设公司天凡建设股份有限公司网站
  • 广州优质网站建设案例一键制作网站
  • 自适应网站如何做mip网页凌晨三点看的片免费
  • 推荐微网站建设wordpress 加上广告
  • 本地的丹阳网站建设深圳手机端网站建设设计公司
  • 昆明网站建设推荐wordpress临时关闭站点
  • 微网站可以自己做吗宁波市住宅建设集团网站
  • 扬中网站建设案例wordpress 多条件查询数据库
  • app软件开发就是网站开发吗天商阳光网站邮箱
  • 龙华做企业网站wordpress 应用店商
  • 北京怀柔网站制作医疗网站设计网站
  • 青岛做公司网站的多吗广州网站建设价格
  • php做网站python做什么网站商场模板
  • 专做ppt的网站wordpress 3.9
  • 二级网站怎样做排名视频建设网站
  • 网站内怎样做关键词有效果凯里网站设计公司
  • 网站备案ps258做网站怎么样
  • 用js做网站登录wordpress获得当前文章的相关文章
  • 网站权重如何提高阿里云服务器可以做彩票网站吗
  • 揭阳响应式网站价格百度云资源搜索
  • 传奇怎么做充值网站山西网站建设营销什么价格
  • 网站开发市场前景seo网站建站公司的主页
  • 建设银行流水网站好看的美食怎么做视频网站
  • wordpress淘宝客建站教程wordpress的链接