记Spring HTTP Invoker远程调用的使用(一)基于Url映射方式,DispatcherServlet统一处理实现


一、概念

Spring HTTP Invoker是spring框架中的一个远程调用模型,基于HTTP协议的远程调用。使用java的序列化机制在网络上传递对象。由Spring提供服务端和客户端。

两种实现方式:

1.基于Url映射方式,客户端远程请求的方式同SpringMVC的controller类似,所有的请求通过在web.xml中的 org.springframework.web.servlet.DispatcherServlet统一处理,根据url映射查找跟请求的url匹配的bean配置(本文通过applicationContext-servers.xml文件管理服务端bean)

2.基于Servlet方式,由org.springframework.web.context.support.HttpRequestHandlerServlet去拦截url- pattern匹配的请求,查找对应的bean配置(本文通过applicationContext-servers.xml文件管理服务端bean)。

二、代码实现

1. 创建项目

项目结构如下:

说明:

项目结构自行决定,我的基于maven的java项目shofacade,web项目shoservice和showebsite都是做为module放在一个父项目中,目的方便接口代码的共享和运行测试。

另外,关于子父项目的构建请参考:简要记录构建Maven父子项目_maven创建子项目-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/u011529483/article/details/132455031?spm=1001.2014.3001.5501

2. 服务端实现

建立实体对象User类,并实现Serializable(对象的序列化,反序列化一定要有)

User.java

package com.wqbr.shoservice.q1001.domain;

import java.io.Serializable;

public class User implements Serializable {

    private static final long serialVersionUID = 1L;

    private String uname;
    private String pwd;
    private boolean disable;

    public String getUname() {
        return uname;
    }

    public void setUname(String uname) {
        this.uname = uname;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public boolean getDisable() {
        return disable;
    }

    public void setDisable(boolean disable) {
        this.disable = disable;
    }
}

定义接口类Q1001Service.java

package com.wqbr.shoservice.q1001.service;

import com.wqbr.shoservice.q1001.domain.User;

/**
 *
 *
 * @author lv
 * @date 2024年8月20日
 */
public interface Q1001Service {

    /**
     * 查询用户
     * @param uname
     * @return
     */
    public User findByUser(String uname);
}

User.java和Q1001Service.java类被我提取到了shofacade模块中,然后以jar包的形式引入到服务端shoservice和客户端showebsite项目中。你也可以不提取,那么在服务端项目和远程客户端项目中你都必须定义相同包路径下的User.java和Q1001Service.java类。

shofacade模块结构:

shofacade模块的pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>

<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/xsd/maven-4.0.0.xsd">
  <!--添加父类项目-->
  <parent>
    <artifactId>sho</artifactId>
    <groupId>com.wqbr</groupId>
    <version>1.0.0</version>
  </parent>

  <modelVersion>4.0.0</modelVersion>

  <artifactId>shofacade</artifactId>
  <packaging>jar</packaging>
  <name>shofacade</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <build>
    <finalName>shofacade</finalName>
  </build>

</project>

shoservice模块中进行接口实现(shoservice为服务端项目):

定义接口实现类Q1001ServiceImpl.java

package com.wqbr.shoservice.q1001.service.impl;

import com.wqbr.shoservice.q1001.domain.User;
import com.wqbr.shoservice.q1001.service.Q1001Service;
import org.springframework.stereotype.Service;

/**
 *
 *
 * @author lv
 * @date 2024年8月20日
 */
@Service
public class Q1001ServiceImpl implements Q1001Service {

    @Override
    public User findByUser(String uname) {
        User user=new User();
        user.setUname("你好!"+uname);
        user.setPwd("123456");
        user.setDisable(true);
        return user;
    }
}

***配置是重点***

配置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/aop"
       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-3.1.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd
                        http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
    <!--配置spring创建容器时要扫描的包--><!--同时也是 MyBatis托管的包路径-->
    <!-- use-default-filters 属性不写默认是为true,表示使用默认的过滤器规则
    use-default-filters="false"表示不扫描base-package指定下的所有java类,并不将注解annotation标注的类注册成IOC容器的bean。
    use-default-filters="true"表示扫描base-package指定下的所有java类,并将注解annotation标注的类注册成IOC容器的bean。
    要注意的是:若使用include-filter去定制扫描内容,要在use-default-filters="false"的情况下,不然会“失效”,被默认的过滤机制所覆盖
    <context:exclude-filter>:与<context:include-filter> 相反,用来告知哪些类不需要注册成Spring Bean,
    同样注意的是:在use-default-filters="false"的情况下,exclude-filter是针对include-filter里的内容进行排除。
    -->
    <context:component-scan base-package="com.wqbr.shoservice">
        <!--<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>-->
        <context:exclude-filter type="regex" expression=".controller.*"/>
        <!--过滤器type类型除了annotation、regex还有assignable、aspectj、custom-->
    </context:component-scan>

</beans>

配置web.xml文件:

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0" 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">
  <!--  https://blog.csdn.net/qyb19970829/article/details/110100544 配置时注意关于spring容器加载顺序的问题,
   applicationContext.xml,spring-security.xml,springmvc.xml 即这几个配置文件加载顺序
   -->
  <!--字符编码过滤器一定要放在前面,在web.xml中配置Spring提供的过滤器类-->
  <filter>
    <filter-name>encodingFilter</filter-name> <!--encodingFilter 这个命名不要修改-->
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <async-supported>true</async-supported>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!--配置Spring的监听器,启动spring容器-->
  <!--配置加载类路径的配置文件,注意加载顺序-->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
      classpath:spring/applicationContext.xml
    </param-value>
  </context-param>
  <display-name>Archetype Created Web Application</display-name>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <!--配置前端控制器,对浏览器发送的请求进行统一处理-->
  <servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!--加载springmvc.xml配置文件的位置和名称,配置的是Spring配置-->
    <init-param>
      <!--contextConfigLocation:上下文配置路径,固定值-->
      <param-name>contextConfigLocation</param-name>
      <!--classpath:类路径,指的是Java和resources文件夹-->
      <!--springmvc.xml:指的是配置文件的名称:需要配置springmvc.xml,在下面。
      spring默认配置文件为applicationContext.xml。当中配置spring创建容器时要扫描的包 已经整合到springmvc.xml中-->
      <param-value>
        classpath:spring/applicationContext-servers.xml
      </param-value>
    </init-param>
    <!--配置启动加载-->
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

</web-app>

web.xml文件中配置了DispatcherServlet进行请求拦截,根据请求的url匹配applicationContext-servers.xml文件中的bean从而调用到服务端的接口方法。

配置applicationContext-servers.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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="q1001ServiceImpl" class="com.wqbr.shoservice.q1001.service.impl.Q1001ServiceImpl"/>
    <!-- 通过Spring HttpInvoker机制暴露远程访问服务 -->
    <bean name="/q1001Service" id="q1001ServiceExporter" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
        <property name="service" ref="q1001ServiceImpl"/>
        <property name="serviceInterface" value="com.wqbr.shoservice.q1001.service.Q1001Service" />
    </bean>
</beans>

文件中配置了id="q1001ServiceImpl"的bean,接口的实现类。

id="q1001ServiceExporter"的bean,Spring HttpInvoker机制暴露的远程访问服务。实现类org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter。<property name="service" ref="q1001ServiceImpl"/>注入接口实现类。<property name="serviceInterface" value="com.wqbr.shoservice.q1001.service.Q1001Service" />定义的接口类。

shoservice模块结构:

shoservice模块的pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>

<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/xsd/maven-4.0.0.xsd">
  <!--添加父类项目-->
  <parent>
    <artifactId>sho</artifactId>
    <groupId>com.wqbr</groupId>
    <version>1.0.0</version>
  </parent>

  <modelVersion>4.0.0</modelVersion>

  <artifactId>shoservice</artifactId>
  <packaging>war</packaging>
  <name>shoservice</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <spring.version>5.2.12.RELEASE</spring.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.wqbr</groupId>
      <artifactId>shofacade</artifactId>
      <version>1.0.0</version>
      <type>jar</type>
      <scope>compile</scope>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${spring.version}</version>
    </dependency>

    <!-- junit测试包 -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <!--添加XMl文件打包配置-->
  <build>
    <resources>
      <resource>
        <!--对应的项目目录-->
        <directory>src/main/java</directory>
        <includes>
          <!--包含的文件-->
          <include>**/*.xml</include>
        </includes>
        <filtering>true</filtering>
      </resource>
      <resource>
        <directory>src/main/resources</directory>
        <includes>
          <include>**/*.properties</include>
          <include>**/*.xml</include>
        </includes>
      </resource>
    </resources>
  </build>
</project>

3. 客户端实现

配置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/aop"
       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-3.1.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd
                        http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
    <!--配置spring创建容器时要扫描的包--><!--同时也是 MyBatis托管的包路径-->
    <!-- use-default-filters 属性不写默认是为true,表示使用默认的过滤器规则
    use-default-filters="false"表示不扫描base-package指定下的所有java类,并不将注解annotation标注的类注册成IOC容器的bean。
    use-default-filters="true"表示扫描base-package指定下的所有java类,并将注解annotation标注的类注册成IOC容器的bean。
    要注意的是:若使用include-filter去定制扫描内容,要在use-default-filters="false"的情况下,不然会“失效”,被默认的过滤机制所覆盖
    <context:exclude-filter>:与<context:include-filter> 相反,用来告知哪些类不需要注册成Spring Bean,
    同样注意的是:在use-default-filters="false"的情况下,exclude-filter是针对include-filter里的内容进行排除。
    -->
    <context:component-scan base-package="com.wqbr.showebsite">
        <!--<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>-->
        <context:exclude-filter type="regex" expression=".controller.*"/>
        <!--过滤器type类型除了annotation、regex还有assignable、aspectj、custom-->
    </context:component-scan>

</beans>

配置springmvc.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">

    <!--配置spring创建容器时要扫描的包-->
    <!-- use-default-filters 属性不写默认是为true,表示使用默认的过滤器规则
    use-default-filters="false"表示不扫描base-package指定下的所有java类,并不将注解annotation标注的类注册成IOC容器的bean。
    use-default-filters="true"表示扫描base-package指定下的所有java类,并将注解annotation标注的类注册成IOC容器的bean。
    要注意的是:若使用include-filter去定制扫描内容,要在use-default-filters="false"的情况下,不然会“失效”,被默认的过滤机制所覆盖
    <context:exclude-filter>:与<context:include-filter> 相反,用来告知哪些类不需要注册成Spring Bean,
    同样注意的是:在use-default-filters="false"的情况下,exclude-filter是针对include-filter里的内容进行排除。
    base-package="com.wqbr.wqdemotwo.controller"
    -->
    <context:component-scan base-package="com.wqbr.showebsite.controller" use-default-filters="false">
        <!--include-filter设置只扫描Controller注解的类-->
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

    <!--处理映射器-->
    <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
    <!--处理器适配器-->
    <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>

    <!--配置JSP视图解析器-->
    <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/"></property> <!--规定跳转页面路径的前缀-->
        <property name="suffix" value=".jsp"></property> <!--规定跳转页面的后缀-->
    </bean>

    <!-- 配置spring开启注解mvc的支持  默认就是开启的 ,要想让其他组件(不包含映射器、适配器、处理器)生效就必须需要配置了-->
    <mvc:annotation-driven/>
    <!-- 让默认servlet处理静态资源。将springMVC不能处理的请求交给servlet,一般用来放行静态资源 -->
    <mvc:default-servlet-handler/>

</beans>

配置web.xml文件:

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0" 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">
  <!--  https://blog.csdn.net/qyb19970829/article/details/110100544 配置时注意关于spring容器加载顺序的问题,
   applicationContext.xml,spring-security.xml,springmvc.xml 即这几个配置文件加载顺序
   -->
  <!--字符编码过滤器一定要放在前面,在web.xml中配置Spring提供的过滤器类-->
  <filter>
    <filter-name>encodingFilter</filter-name> <!--encodingFilter 这个命名不要修改-->
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <async-supported>true</async-supported>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!--配置Spring的监听器,启动spring容器-->
  <!--配置加载类路径的配置文件,注意加载顺序-->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
      classpath:spring/applicationContext.xml
      classpath:spring/applicationContext-clients.xml
    </param-value>
  </context-param>
  <display-name>Archetype Created Web Application</display-name>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <!--配置前端控制器,对浏览器发送的请求进行统一处理-->
  <servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!--加载springmvc.xml配置文件的位置和名称,配置的是Spring配置-->
    <init-param>
      <!--contextConfigLocation:上下文配置路径,固定值-->
      <param-name>contextConfigLocation</param-name>
      <!--classpath:类路径,指的是Java和resources文件夹-->
      <!--springmvc.xml:指的是配置文件的名称:需要配置springmvc.xml,在下面。
      spring默认配置文件为applicationContext.xml。当中配置spring创建容器时要扫描的包 已经整合到springmvc.xml中-->
      <param-value>
        classpath:spring/springmvc.xml
      </param-value>
    </init-param>
    <!--配置启动加载-->
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <!--开启项目时打开的页面-->
    <welcome-file-list>
      <welcome-file>/login.jsp</welcome-file>
    </welcome-file-list>

  <!--设置session超时,单位分钟 默认30分钟-->
  <!--  <session-config>-->
  <!--    <session-timeout>2</session-timeout>-->
  <!--  </session-config>-->

</web-app>

web.xml配置文件中加载了applicationContext-clients.xml文件,applicationContext-clients.xml文件进行Spring HTTP Invoker客户端远程调用的实现。

配置applicationContext-clients.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"
	   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<bean id="q1001Service" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
		<!--<property name="serviceUrl" value="http://192.168.1.86:7001/shoservice-1.0.0/q1001Service" />-->
		<property name="serviceUrl" value="http://127.0.0.1:7001/shoservice-1.0.0/q1001Service" />
		<property name="serviceInterface" value="com.wqbr.shoservice.q1001.service.Q1001Service" />
	</bean>

</beans>

文件中定义了id="q1001Service"的bean,实现HTTP客户端请求的代理类org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean。name="serviceUrl"属性指定远程服务的调用地址,/q1001Service为服务端暴露的接口服务。name="serviceInterface"指定调用的接口。

编写MyTestController.java类调用远程服务:

package com.wqbr.showebsite.controller;

import com.wqbr.shoservice.q1001.domain.User;
import com.wqbr.shoservice.q1001.service.Q1001Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author lv
 * @date 2023年9月24日
 *
 */
@Controller
@RequestMapping("/myTest")
public class MyTestController {

    @Autowired
    private Q1001Service q1001Service;

    /**
     * 处理超链接发送出来的请求
     * @param model
     * @return
     */
    @RequestMapping(path = "/hello")
    public String sayHello(Model model){
        System.out.println("入门方法执行了2...");
        long currentTimeMillis = System.currentTimeMillis();
        User user=q1001Service.findByUser("你好 ! xiao  xiao  xiao xiao 强123");
        System.out.println("获得信息 耗时:"+(System.currentTimeMillis()-currentTimeMillis)+"毫秒--"+user.getUname()+"-=-=-"+user.getPwd()+"-==-=-"+user.getDisable());
        // 向模型中添加属性msg与值,可以在html页面中取出并渲染
        model.addAttribute("msg","hello,SpringMVC");
        // 配置了视图解析器后,写法
        return "index";
    }
}

类中自动装配了private Q1001Service q1001Service;也就是applicationContext-clients.xml文件中的bean,并调用了findByUser()方法。

shoservice模块结构:

shoservice模块的pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>

<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/xsd/maven-4.0.0.xsd">
  <!--添加父类项目-->
  <parent>
    <artifactId>sho</artifactId>
    <groupId>com.wqbr</groupId>
    <version>1.0.0</version>
  </parent>

  <modelVersion>4.0.0</modelVersion>

  <artifactId>showebsite</artifactId>
  <packaging>war</packaging>
  <name>showebsite</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <spring.version>5.2.12.RELEASE</spring.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.wqbr</groupId>
      <artifactId>shofacade</artifactId>
      <version>1.0.0</version>
      <type>jar</type>
      <scope>compile</scope>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${spring.version}</version>
    </dependency>

    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
      <version>4.5.2</version>
    </dependency>
  </dependencies>
</project>

到此,代码实现完毕。我们在weblogic中运行项目:

点击页面的入门程序发送请求

得到控制台的打印结果如下,远程调用服务成功。


补充,sho父工程的pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.wqbr</groupId>
    <artifactId>sho</artifactId>
    <packaging>pom</packaging>
    <version>1.0.0</version>
    <name>sho</name>

    <!--添加子项目模块-->
    <modules>
        <module>shoservice</module>
        <module>showebsite</module>
        <module>shofacade</module>
    </modules>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.1.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <attach>true</attach>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

本篇到此结束,

  • 8
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值