Spring Boot - how to enable a REST endpoint from a dependency?

I am new to Spring / Spring Boot, so I apologize if what I ask is trivial.

I created a Spring boot application that provides a REST endpoint:

package com.atomic.contentguard;

...
@Controller
@RequestMapping("/rest")
public class AcgController {

@RequestMapping(value="/acg-status",method=RequestMethod.GET)
@ResponseBody
 public String getStatus(){     
    return "Hi there!";
 }
}

Everything works fine, when you run it as a standalone Spring application to load, the endpoint can be verified by going to http: // localhost: 8080 / rest / acg-status .

What I want to achieve is to “bring it” to another application that will include my application as a dependency in pom.xml, waiting for this REST endpoint to appear.

What I have done so far includes it in another pom.xml project like:

</dependencies>
    ...
    <dependency>
        <groupId>com.atomic</groupId>
        <artifactId>contentguard</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

And then included it in this other @ComponentScan application in the configuration file section:

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.atomic.contentguard"})
public class EnvInfoWebConfig extends WebMvcConfigurerAdapter {

}

, :

No mapping found for HTTP request with URI [/other-application-context/rest/acg-status] in DispatcherServlet with name 'envinfo-dispatcher'

/- ?

+4
1

, spring , ( WebMvcConfigurerAdapter):

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages = { "com.atomic.contentguard"})
public class AcgLauncher extends SpringBootServletInitializer {

    //This method is required to launch the ACG application
    public static void main(String[] args) {

        // Launch Trainserv Application
        SpringApplication.run(AcgLauncher.class, args);
    }
}

Spring Boot spring (, , ).

0

Source: https://habr.com/ru/post/1659199/


All Articles