为了账号安全,请及时绑定邮箱和手机立即绑定

万能的hello world!

万能的hello world!
源码地址
https://gitee.com/liuerchong/news-artical

业务及系统服务调用关系说明
artical-clnews 服务:用户自己发布文章及通过爬虫爬取过来的所有文章

artical-examined 服务:管理员调用artical-clnews 服务 对文章进行审核,审核通过的文章进行发布

atical-clnews 工程项目搭建
pom<?xml version="1.0" encoding="UTF-8"?>


news-artical
com.liu.news
1.0-SNAPSHOT

4.0.0

<artifactId>artical-clnews</artifactId>

<dependencies>

    <dependency>
        <groupId>com.liu.news</groupId>
        <artifactId>artical-common-public</artifactId>
    </dependency>
    <dependency>
        <groupId>com.liu.news</groupId>
        <artifactId>artical-common-db</artifactId>
    </dependency>
    <dependency>
        <groupId>com.liu.news</groupId>
        <artifactId>artical-common-utils</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
配置文件 bootstrap.yml server: port: 8070 spring: main: allow-bean-definition-overriding: true profiles: active: dev application: name: artical-clnews cloud: nacos: discovery: username: nacos password: nacos server-addr: 172.17.169.81:8848 #namespace: b561281a-fb95-411e-b75b-cf36bfc90854 #config: #server-addr: ${spring.cloud.nacos.discovery.server-addr} #file-extension: properties #namespace: b561281a-fb95-411e-b75b-cf36bfc90854 #group: payment

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;

/**

  • @author lx

  • @version 1.0

  • @description: TODO

  • @date 2021/7/16 16:21
    */
    @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;

/**

前端控制器

@author liuerchong

@since 2021-07-16
*/
@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<?xml version="1.0" encoding="UTF-8"?>


news-artical
com.liu.news
1.0-SNAPSHOT

4.0.0

<artifactId>artical-examined</artifactId>

<dependencies>

    <dependency>
        <groupId>com.liu.news</groupId>
        <artifactId>artical-common-public</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-undertow</artifactId>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-openfeign -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
    <dependency>
        <groupId>com.squareup.okhttp3</groupId>
        <artifactId>okhttp</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-loadbalancer -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-loadbalancer</artifactId>
    </dependency>
</dependencies>

配置文件
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

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消