2017-05-09 39 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這個註解時,它只掃描你放置它的包.......希望這有助於。

相關問題