美文网首页
Could not resolve placeholder 'n

Could not resolve placeholder 'n

作者: simians | 来源:发表于2019-02-23 12:25 被阅读0次

    我在配置spring cloud config client 时报错:
    Could not resolve placeholder 'name' in value "${name}"
    我在git 仓库里创建了application-dev.properties


    application-dev.properties.png

    我的配置在application.yml

    spring:
      application:
        name: user
      cloud:
        config:
          label: master
          profile: dev
          name: application
          uri: http://localhost:8774/
    

    解决方法时创建一个bootstrap.yml 文件将spring.cloud.config下的配置移到这个地方就行了
    如下图


    image.png

    这样就不会报错了也可以获取到值了

    image.png
    package com.simianBook.controller;
    
    import com.simianBook.domain.BookBean;
    import com.simianBook.domain.UserBean;
    import com.simianBook.service.feignService.BookService;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.ResponseBody;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @ResponseBody
    public class UserController {
        @Value("${name}")
        String name;
        @Autowired
        BookService bookService;
        @GetMapping("/getUser/{userID}")
        public UserBean getUser(String userID){
            System.out.println("userID:++++"+userID);
            return new UserBean("1","simian",77,188,"河南省");
        }
        @GetMapping("/getBookDetail/{bookId}")
        public BookBean getBook(@PathVariable Integer bookId){
            System.out.println("userId:"+bookId);
            return bookService.getBook("1");
        }
        @GetMapping("/getData")
        public String getData(){
            return name;
        }
    }
    
    

    相关文章

      网友评论

          本文标题:Could not resolve placeholder 'n

          本文链接:https://www.haomeiwen.com/subject/ckzuyqtx.html