zoukankan      html  css  js  c++  java
  • httpInvoke的springboot项目打包成jar包作为工具包

    日前接收一个项目,需求是做httpInvoke的工具jar包,为第三方的(非spring和springboot)项目调用:

    配置类:

    @Configuration
    public class ClientConfiguration {
        @Bean
        public HttpInvokerProxyFactoryBean testService() {
            HttpInvokerProxyFactoryBean httpInvokerProxyFactoryBean = new HttpInvokerProxyFactoryBean();
            httpInvokerProxyFactoryBean.setServiceUrl("http://localhost:8080/xxxx/remoting");
            httpInvokerProxyFactoryBean.setServiceInterface(IPassengerService.class);
            return httpInvokerProxyFactoryBean;
        }

    将springboot项目打包成jar包,作为工具包导入项目后,找不到jar中的类。

    原因是:springboot项目使用了自动的打包插件。

    原先的插件配置:

    <build>
        <plugins>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
        </plugins>
      </build>

    改为apache的插件:

     

     <build>
        <plugins>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
            <source>1.8</source>
            <target>1.8</target>
          </configuration>
        </plugins>
      </build>

    第三方的调用:

    首先引入jar包:

     调用实例:

    ApplicationContext applicationContext=new AnnotationConfigApplicationContext(ClientConfiguration.class);    
                IPassengerService serivce = applicationContext.getBean(IPassengerService.class);
                   serivce.findUserName(aa, "cc");   //findUserName 为IPassengerService方法
  • 相关阅读:
    dynamic 转换实体类
    泛型的简单使用
    winfrom嵌入word
    echart睡眠后台代码,
    echart实现睡眠前台代码
    Mysql时间加一天
    一道关于面向对象面试题所引发的血案(阿里)
    一道面试题让你彻底掌握JS中的EventLoop(头条)
    对象(数组)的深克隆和浅克隆(头条)
    BAT笔试题中几道关于堆栈内存和闭包作用域的题
  • 原文地址:https://www.cnblogs.com/leeego-123/p/12291310.html
Copyright © 2011-2022 走看看