I am trying to migrate from Jax RS to Spring Rest, I am not sure how to add base address of URL for Spring rest.
I tried adding <mvc:annotation-driven />
, but did not help
<jaxrs:server address="/search-service">
<jaxrs:serviceBeans>
...all service classes
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="wadlGenerator"/>
<ref bean="cors-filter"/>
<ref bean="soaJsonJaxbProvider"/>
<ref bean="exceptionMapper"/>
<ref bean="searchContextProvider"/>
</jaxrs:providers>
</jaxrs:server>
Here is my Controller:
@RestController
@RequestMapping(value = "/search", produces=org.springframework.http.MediaType.APPLICATION_JSON_VALUE,
consumes=org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
public class SearchService {
@PostMapping
public ServiceResponse<searchDTO> search(@RequestHeader HttpHeaders headers, ServiceRequest<searchDTO> request) {
....method
}
How to add Spring rest instead of jaxrs:server in beans.xml.
For spring to discover the annotated class, you need to add the annotation-driven
tag and also component-scan
:
<?xml version="1.0" encoding="UTF-8"?>
<beans> <!-- add in all the namespace declarations you need-->
<context:component-scan base-package="com.yourpackage" />
<mvc:annotation-driven />
</beans>
The alternative is to use AnnotationConfigApplicationContext
when you load the spring context, which is a fully java / annotation configured setup instead of the XML config.
For the gory details, refer to the spring docs https://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/beans.html#beans-factory-metadata :
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.