zoukankan      html  css  js  c++  java
  • spring boot配置service发布服务

    在application.yml中配置

    server:
      port: 8080
      context-path: /crm
    spring:
      datasource:
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://localhost:3306/crm
        username: root
        password: 136735
      jpa:
        show-sql: true
      jackson:
        default-property-inclusion: non_null
      devtools:
        restart:
          enabled: true
    cxf:
      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发布服务

    package top.kylewang.crm.controller;
    
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    import javax.ws.rs.Consumes;
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    
    @Path("path")
    @Service
    @Transactional(rollbackFor = Exception.class)
    public class TestPath {
        @Path("/p1")
        @GET
        @Consumes({"application/xml", "application/json"})
        public String getString() {
            return "path";
        }
    }

    访问 http://localhost:8080//crm/services/path/p1

    返回path

    带参数的请求。

    @Path("QueryProductService")
    public interface QueryProductService {
        /**
         * 查询商品根据Uid
         * @return
         */
        @Path("/QueryProductBypid")
        @GET                                                //post 参数在请求体中,get在url中
        @Consumes({"application/xml", "application/json"})    //返回void用consumes
        Product QueryProductBypid(@QueryParam("id") String id);
    }

    url  http://127.0.0.1:9001/background/services/QueryProductService/QueryProductBypid?id=556556887752

  • 相关阅读:
    org.apache.commons.io.FilenameUtils 常用的方法
    (转)同一服务器部署多个tomcat时的端口号修改详情
    JavaWeb中监听器+过滤器+拦截器区别、配置和实际应用
    idea tomcat服务器运行打印日志到控制台是乱码解决方案
    spring boot 添加整合ssl使得http变成https方法
    Fiddler 抓包工具总结
    一些概念
    观点汇总
    Spring 问题总结
    tomcat和jetty区别
  • 原文地址:https://www.cnblogs.com/liyafei/p/8485616.html
Copyright © 2011-2022 走看看