万能的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-11-14企业协同软件:现代化管理的新选择
- 2024-11-14职场协作不再混乱:8个团队管理技巧提升你的项目效率
- 2024-11-14想让Excel表格设计更美观?试试这几款好用工具!
- 2024-11-14导航效果资料:初学者必备指南
- 2024-11-14制作右侧跟随效果资料的简单教程
- 2024-11-14职场效率倍增!学会这6个任务管理法则轻松完成工作
- 2024-11-14PS网页切图资料:新手入门教程
- 2024-11-14如何使用API查询虚拟货币的实时行情
- 2024-11-14低代码应用入门指南:轻松创建你的第一个应用
- 2024-11-14实物量法到底是什么?让项目管理更精准的秘密