2017-05-09 38 views
0

我的主要入门级与“无消息”从Spring应用程序

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(); 
    } 
} 

如果你的春天代码结构错误页面是这样的,你尝试运行该应用程序,不要惊讶,以获得错误的Web控制台。

对不起家伙对我的英语不好....

回答

0

这个问题的解决将是我们的包在嵌套顺序,如果你看一下代码包没有嵌套,而放置在同一个文件夹/包“项目”。

取而代之的是: -

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这个注解时,它只扫描你放置它的包.......希望这有助于。

相关问题