因此,我尝试在带有Spring注释的Spring Tool Suite中编写一个基本的Rest Controller,在该端点上单击端点“ / health”,并且在单击该端点“ Kafka Streaming App状况良好”时收到以下消息。
当我在浏览器上检查并且已经尝试记录日志时,我收到的唯一错误是404状态错误,请提供帮助。我认为问题可能出在Spring中我如何在Main Application类中调用Controller。
主应用程序类
package com.eds.kafka.streaming.app; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; //import org.springframework.data.jpa.repository.config.EnableJpaRepositories; //@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) //@Configuration //@EntityScan(basePackages = {"com.eds.kafka.streaming.model"}) //@ComponentScan(basePackages = { "com.eds.kafka.streaming.service", "com.eds.kafka.streaming.util", "com.eds.kafka.streaming.config", "com.eds.kafka.streaming.controller"}) //"com.tmobile.eds.infosec.volt.encr", @ComponentScan(basePackages = {"com.eds.kafka.streaming"}) @SpringBootApplication public class KafkaStreamingAppContainerApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(KafkaStreamingAppContainerApplication.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(KafkaStreamingAppContainerApplication.class); } }
控制器类
package com.eds.kafka.streaming.controller; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.PropertySource; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; @EnableAutoConfiguration @PropertySource("classpath:application-${spring.profiles.active}.properties") @RestController public class MainController { @RequestMapping(method = RequestMethod.GET, value = "/health", produces = "application/json") @ResponseBody public ResponseEntity home() { System.out.println("Controller being configured!"); return new ResponseEntity("Kafka Streaming App is Healthy", HttpStatus.OK); } }
如果您有任何建议,请告诉我,如果需要,我可以提供项目的压缩版本,只是给我发消息。