在application.yml中配置
server: port: 8080context-path: /crm spring: datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/crm username: root password: 136735jpa: show-sql: truejackson: default-property-inclusion: non_null devtools: restart: enabled: truecxf: path: /services #使用service发布服务,需要在/crm后面加上/service,
#要添加依赖:否则解析不了,做不了映射 "org.apache.cxf:cxf-spring-boot-starter-jaxrs:$boot_starter_jaxrs_version"
servlet.init: service-list-path: /info jaxrs: component-scan: true
service发布服务
packagetop.kylewang.crm.controller; importorg.springframework.stereotype.Service; importorg.springframework.transaction.annotation.Transactional; importorg.springframework.web.bind.annotation.ResponseBody; importjavax.ws.rs.Consumes; importjavax.ws.rs.GET; importjavax.ws.rs.Path; @Path("path") @Service @Transactional(rollbackFor = Exception.class) public classTestPath { @Path("/p1") @GET @Consumes({"application/xml", "application/json"}) publicString getString() { return "path"; } }
访问http://localhost:8080//crm/services/path/p1
返回path
带参数的请求。
@Path("QueryProductService") public interfaceQueryProductService { /*** 查询商品根据Uid * @return */@Path("/QueryProductBypid") @GET //post 参数在请求体中,get在url中 @Consumes({"application/xml", "application/json"}) //返回void用consumes Product QueryProductBypid(@QueryParam("id") String id); }
urlhttp://127.0.0.1:9001/background/services/QueryProductService/QueryProductBypid?id=556556887752