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方法
原文地址:https://www.cnblogs.com/leeego-123/p/12291310.html