微服务--1.微服务场景模拟遇到的问题

错误1:
I/O error on GET request for “http://user-service/hi”: user-service; nested exception is java.net.UnknownHostException: user-service

微服务--1.微服务场景模拟遇到的问题_第1张图片
解决错误1的方法:
添加依赖:

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <version>2.1.2.RELEASE</version><!--服务器有可不写-->
</dependency>

错误2:访问网页出现服务器500错误

Thu Dec 26 16:54:54 CST 2019
There was an unexpected error (type=Internal Server Error, status=500).
Error resolving template [Country{id=1, countryname='Angola', countrycode='AO'}Country{id=2, countryname='Afghanistan', countrycode='AF'}Country{id=3, countryname='Albania', countrycode='AL'}Country{id=4, countryname='Algeria', countrycode='DZ'}Country{id=5, countryname='Andorra', countrycode='AD'}Country{id=6, countryname='Anguilla', countrycode='AI'}Country{id=7, countryname='Antigua and Barbuda', countrycode='AG'}Country{id=8, countryname='Argentina', 
..............................................................
countryname='Zambia', countrycode='ZM'}], template might not exist or might not be accessible by any of the configured Template Resolvers
	at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869)
	at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:607)
	at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098)
	at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072)
	at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:362)
	at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:189)
..............................................................
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

解决办法:
修改这个Maven小项目的controller中的注解----@Controller改为@RestController
错误3:Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
解决办法:
添加依赖:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.8.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
</parent>
	

错误4: public static void main(String[] args) { SpringApplication.run (ConsumerApplication.class,args); }
Error:(12, 30) java: 无法访问org.springframework.context.ConfigurableApplicationContext
找不到org.springframework.context.ConfigurableApplicationContext的类文件
微服务--1.微服务场景模拟遇到的问题_第2张图片
解决办法:
(1):第一次出现这个错误的原因是因为父类工程不是springboot项目,或者说这个小项目中缺少springboot的依赖,我直接把springboot相关依赖手动导入报错,因为依赖缺少版本号,所以就直接删掉整个项目,重新新建了一个springboot项目,后来我想直接把这个小项目删掉,在新建一个springboot的Model项目就好啦!
(2):如果你新建了一个springboot的Model项目,这个错误还在那就用这个方法:
微服务--1.微服务场景模拟遇到的问题_第3张图片
这里开始时开始时选中的,我们把他取消就好了
错误5:Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured
微服务--1.微服务场景模拟遇到的问题_第4张图片
解决办法:
排除此类的autoconfig。启动以后就可以正常运行。
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})

你可能感兴趣的:(微服务--1.微服务场景模拟遇到的问题)