万能的hello world!
2021/7/22 3:05:44
本文主要是介绍万能的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>
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
这篇关于万能的hello world!的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-22初创企业的效率秘诀!实用的看板式任务管理工具推荐
- 2024-12-22新能源汽车销售难题如何破?看板工具助力门店管理升级
- 2024-12-218 款现代无代码工具,轻松提升开发者工作效率 ???????
- 2024-12-21从线索跟踪到业绩提升:销售任务管理系统推荐
- 2024-12-21刚刚发布RobinReach:多渠道社交媒体管理工具 ??
- 2024-12-21跨地域协作无压力!推荐几款必备的可视化协同工具
- 2024-12-21初学者指南:轻松掌握文章编辑器
- 2024-12-21Excel数据导出教程:让数据迁移变得简单
- 2024-12-21Excel数据导入入门教程
- 2024-12-215分钟速览:优化项目管理必备的5款高效工具