I'm developing a simple Spring-based web service userSetting
to run on Liberty 8.5.5.9. I'm able to build and deploy the service, and when I start it, it appears to understand its context root (userSetting
) but none of its endpoints; I believe I'm missing some essential Spring-based linkage of the parts of the application, but can't figure out which.
The main class of the application looks like:
@SpringBootApplication
@ImportResource("classpath:spring-resource1.xml")
@Import({RESTInterface.class})
public class UserSettingApplication {
private static final LoggerUtils logger = new LoggerUtils( UserSettingApplication.class );
public static void main(String[] args) {
logger.debug( "Entering UserSettingApplication.main()" );
System.out.println( "Entering UserSettingApplication.main()" );
SpringApplication.run(UserSettingApplication.class, args);
logger.debug( "Exiting UserSettingApplication.main()" );
System.out.println( "Exiting UserSettingApplication.main()" );
}
// Dan Vega says: Remember that this going to execute after the
// application context is loaded so you could use it to check if
// certain beans exist or what values of certain properties are.
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
logger.info("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
logger.info(beanName);
}
};
}
}
and the class that defines the endpoints (abbreviated to a single end point) is:
@CrossOrigin
@RestController
@RequestMapping(path = "userSetting")
public class RESTInterface {
...
@RequestMapping(path = "/hello", method = { RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public String hello() {
return "Hello, dude!";
}
}
when I try to hit the endpoint http://localhost:9080/userSetting/userSetting/hello
, I get the message:
Error 404: java.io.FileNotFoundException: SRVE0190E: File not found: /userSetting/hello
It appears that the RestController
has not gotten properly hooked up to the application; in desperation, I tried adding the following line to the main class:
@Import({RESTInterface.class})
but this didn't change anything. Can someone please tell me how to properly connect in the endpoints?