首页 > IT职业 > IT生活 > 万能的hello world!
万能的hello world!
源码地址
https://gitee.com/liuerchong/news-artical
业务及系统服务调用关系说明
artical-clnews 服务:用户自己发布文章及通过爬虫爬取过来的所有文章
artical-examined 服务:管理员调用artical-clnews 服务 对文章进行审核,审核通过的文章进行发布
atical-clnews 工程项目搭建
pom
news-artical
com.liu.news
1.0-SNAPSHOT
4.0.0
artical-clnews com.liu.news artical-common-public com.liu.news artical-common-db com.liu.news artical-common-utils org.springframework.boot spring-boot-starter-web application.yml
spring:
application:
name: artical-clnews-servcie
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver #数据库驱动包
url: jdbc:mysql://localhost:3307/artical?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true
username: root
password: root
mybatis-plus:
global-config:
db-config:
field-strategy: not_empty
#驼峰下划线转换
column-underline: true
#逻辑删除配置
logic-delete-value: 0
logic-not-delete-value: 1
db-type: mysql
refresh: false
configuration:
map-underscore-to-camel-case: true
cache-enabled: false
启动类package com.liu.news.artical.clnews;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient
public class ClnewsApplication {
public static void main(String[] args) throws InterruptedException{
SpringApplication.run(ClnewsApplication.class, args);
}
}
业务类现在只加一个方法,hello
package com.liu.news.artical.clnews.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/cl-news")
public class ClNewsController {
@GetMapping("/hello")
public String hello(){
return “hello world”;
}
}
测试
启动工程2021-07-19 14:12:23.818 INFO 20820 — [ main] c.a.c.n.registry.NacosServiceRegistry : nacos registry, DEFAULT_GROUP artical-clnews-servcie 172.17.169.81:8070 register finished
新建artical-examined 工程
此工程对爬虫或者作者新曾的文章进行审核,插入数据库进行保存
pom
news-artical
com.liu.news
1.0-SNAPSHOT
4.0.0
artical-examined com.liu.news artical-common-public org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-tomcat org.springframework.boot spring-boot-starter-undertow <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-openfeign -->org.springframework.cloud spring-cloud-starter-openfeign com.squareup.okhttp3 okhttp <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-loadbalancer -->org.springframework.cloud spring-cloud-starter-loadbalancer 配置文件
bootstrap.ymlserver:
port: 8090
spring:
#profiles:
#active: dev
application:
main:
allow-bean-definition-overriding: true
name: examined-artical #服务名
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
service类
@FeignClient(value = “artical-clnews-servcie”) 与对用注册中心服务名对应package liu.atical.examined.service;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@Component
@FeignClient(value = “artical-clnews-servcie”)
public interface ArticalClnewsFeignService {
@GetMapping(value = "/cl-news/hello")
public String hello();
}
版权声明:本文为CSDN博主「liuerchong」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/liuerchong/article/details/118898240
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4222/viewspace-2796874/ ,如需转载,请注明出处,否则将追究法律责任。