我使用的是spring-boot
,并要整合一个简单的REST
如下服务。
@Controller
@RequestMapping("/content")
public class MyServiceRest extends SpringBeanAutowiringSupport {
@RequestMapping(method = RequestMethod.GET)
public String test() {
return "OK";
}
}
结果:两个localhost:8080/<app-name>/services/content
结果"No service was found."
。 为什么?
我一定要明确莫名其妙发布服务?
也许这是因为我的分发程序Servlet?
@Bean
public ServletRegistrationBean dispatcherServletRegistration() {
ServletRegistrationBean registration = new ServletRegistrationBean(new CXFServlet(), "/services/*");
registration.setName(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);
return registration;
}
由于您使用的春天启动,请确保您的应用程序是正确设置,通过添加正确的注释。 例如,
@EnableAutoConfiguration
@EnableWebMvc
@Configuration
@ComponentScan
/*
* Application Setups using Spring boot.
*/
public class Application{
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@ EnableWebMvc
是增加了在使用Spring MVC与Spring启动的注解。 然后你可以为你在你的问题做了定义控制器。
与控制器类添加到包@Component
在主类像扫描: @ComponentScan( basePackages = { "your.package.with.controller" } )
发生这种情况时弹簧未初始化(不知道)控制器
你还应该添加URL映射你的方法
@RequestMapping(方法= RequestMethod.GET,值= “url_here”,尝试
@RequestMapping(method = RequestMethod.POST, value = "/",
在春季启动的最新版本,我目前正在使用,Web服务将地址http://localhost:8080/content
此外,I类用于启动该服务如下所示:
@ComponentScan("eu.buzea")
@EnableAutoConfiguration
@EnableTransactionManagement
@SpringBootApplication
public class Application{
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
源代码
https://drive.google.com/open?id=0BzBKpZ4nzNzUWmJmOTFwbTFjWWM
使用扬鞭
HTTP://本地主机:7070 /招摇,ui.html#/
**干杯*
由于当前的spring-boot.1.5.6
存在使用不要求cxf
。
只需使用一个@RestController
与@GetMapping
,并很高兴地访问localhost:8080/content
。