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方法

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM