Spring boot 带有“的错误页面;没有可用的消息”;从Spring应用程序

Spring boot 带有“的错误页面;没有可用的消息”;从Spring应用程序,spring-boot,Spring Boot,我的主要入门课程 package com.project.cloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @EnableDiscoveryCli

我的主要入门课程

package com.project.cloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@EnableDiscoveryClient
@SpringBootApplication
public class HelloworldClientApplication {

    public static void main(String[] args) {
        SpringApplication.run(HelloworldClientApplication.class, args);
    }
}
我的资源文件

   package com.project.controller;

   import org.springframework.beans.factory.annotation.Autowired;
   import org.springframework.web.bind.annotation.GetMapping;
   import org.springframework.web.bind.annotation.RequestMapping;
   import org.springframework.web.bind.annotation.RestController;
   import org.springframework.web.client.RestTemplate;

   /**
   *
   * @author Wasp Networks
   */
    @RestController
    @RequestMapping("/rest/client/helloworld")
    public class HelloResources {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping
    public String Entry(){
        String url = "http://helloworld-server/rest/server/helloworld";
        return restTemplate.getForObject(url, String.class);
    }

    @RequestMapping("/")
    public String Main(){
       return "Helloworld client!.";
    }

}
我的配置类

package com.project.configuration;
/**
*
* @author Wasp Networks
*/
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;


@Configuration
public class Configure {
    @LoadBalanced
    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }
}
如果您的spring代码结构是这样的,并且您尝试运行应用程序,那么在web控制台上出现错误就不必感到惊讶了


对不起,我的英语不好

解决此问题的方法是将我们的包按嵌套顺序放置,如果您查看代码,这些包不是嵌套的,而是放在同一文件夹/包“项目”中

而不是这个:-

    package com.project.cloud;
    package com.project.controller;
    package com.project.configuration;
    package com.project.cloud;
    package com.project.cloud.controller;
    package com.project.cloud.configuration;
执行以下操作:-

    package com.project.cloud;
    package com.project.controller;
    package com.project.configuration;
    package com.project.cloud;
    package com.project.cloud.controller;
    package com.project.cloud.configuration;
在定义了@SpringBootApplication的应用程序的主入口点包下创建其他包,当使用@SpringBootApplication注释时,它只扫描您放置的包……希望这有帮助