简体   繁体   中英

call rest API in project A which is added as a jar dependency to project B

Project 1 --->jar build Project 2--->jar build

Project 2 has dependency of project1.

Now we just run the project 2 locally and then call the api written in Project 1. But the hit to the API isn't happening.

Any idea what i may be missing.Googling didn't help much.

Project A has a rest api configured like this

 @Path("/mytest")
    public interface myApi {
    @PUT
    @Path("/create")
    void create(MyModelmodel);  
}

Implemented as

@Component
public class myApService implements myApi {


   @Autowired
   public myClient myClient;

    @Override
    public void create(MyModel model) {
        myClient.createazureworkspace(model);

    }

}

Added Project 1 as a dependency jar in pom of Project 2

<dependency>
<groupId>com.xxxx</groupId>
<artifactId>project a</artifactId>
<version>1.0.0</version>
</dependency> 

Now when i call http://localhost:8080/mytest/create it doesn't even hit the api Tried adding the below code in Project 2

@Configuration
@ComponentScan(basePackages ="com.basepack.projectA")
public class AppConfig {

}

But it too didn't work

Finally was able to make it work!

  1. One of the issues was a missing @Service over the implementation.
  2. Package names were refactored.
  3. The port I was calling was different from which it was getting started on.

Going through the startup logs helped.

Now the call to the api works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM