为什么我的基于Spring的Web应用程序不响应其定义的端点

时间:2018-04-20 00:03:54

标签: spring websphere-liberty

我正在开发一个基于Spring的简单Web服务userSetting,以便在Liberty 8.5.5.9上运行。我能够构建和部署服务,当我启动它时,它似乎理解了它的上下文根(userSetting)但没有它的端点;我相信我错过了一些基于Spring的应用程序部分的基本链接,但无法弄清楚哪个。

该应用程序的主要类看起来像:

@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);
      }
    };
  }
}

和定义端点的类(缩写为单个端点)是:

@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!";
        }

}

当我尝试点击端点http://localhost:9080/userSetting/userSetting/hello时,收到消息:

Error 404: java.io.FileNotFoundException: SRVE0190E: File not found: /userSetting/hello

出现 RestController未正确连接到应用程序;无奈之下,我尝试将以下行添加到主类:

@Import({RESTInterface.class})

但这并没有改变任何事情。有人可以告诉我如何在端点中正确连接吗?

1 个答案:

答案 0 :(得分:0)

尝试点击http://localhost:9080/userSetting/hello 您在网址中提供了两次“userSetting”