Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
heyuxian committed Dec 20, 2017
1 parent 5ea88f4 commit 3a28d53
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 106 deletions.
83 changes: 10 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ MCloud 基于Spring Cloud进行开发,提供了项目中常用的基础设施
- **mcloud-config** 统一配置中心。
- **mcloud-monitoring** 基于 Spring boot admin 实现系统监控。
- **mcloud-file-storage** 文件存储中心。
- **mcloud-logs** 基于 `Kafka` 以及 `ElasticSearch` 实现服务的日志分析。
- **mcloud-search** 基于 `ElasticSearch` 全文检索服务
- **mcloud-logs** 基于`logstash` `Kafka` 以及 `ElasticSearch` 实现的日志服务。
- **mcloud-blog** Demo Project

其他模块:
Expand All @@ -32,86 +33,22 @@ UI界面:

- **JDK** 1.8 以上
- **IDE** 请安装对应IDE的**lombok**插件
- **数据库** 使用flywaydb进行数据库脚本的版本管理,需执行flywaydb的相关maven命令
- **数据库** Mysql 5.5 及以上
- **缓存** Redis
- **消息中间件** Kafka, RabbitMQ (暂未实现)
- **全文检索** ElasticSearch (暂未实现)
- **其他** Zookeeper (暂未实现)


## 快速使用
## 系统结构

**下载项目**
![1](https://user-images.githubusercontent.com/30259465/34211439-0d4f035c-e5d4-11e7-8c46-ba5c7ffd65d0.png)

```
git clone https://github.com/heyuxian/mcloud.git
cd 项目目录/mcloud
```

**创建数据库**

使用mysql客户端或其它你喜欢的工具创建数据库(默认数据库名称为db_blog):

```shell
CREATE DATABASE IF NOT EXISTS db_blog DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
```

**使用 flywaydb 初始化数据库**

- mcloud-blog/pom.xml

```xml
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>4.2.0</version>
<configuration>
<user>root</user>
<password>root</password>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/db_blog</url>
</configuration>
</plugin>
```

修改Spring 配置文件中的数据库用户名及密码:

- mcloud-blog: application-dev.yml

执行flywaydb相关命令初始化数据库:

```shell
mvn flyway:clean flyway:migrate
```

**启动OAuth Server:** [详细配置](https://github.com/heyuxian/mcloud-oauth2-server)

```
git clone https://github.com/heyuxian/mcloud-oauth2-server
mvn clean install
mvn flyway:clean flyway:migrate
mvn spring-boot:run
```

访问地址: http://localhost:8043/uaa/swagger-ui.html

**启动认证中心:** [详细配置](mcloud-uia/README.md)

```
cd mcloud-uia
mvn clean install
mvn spring-boot:run
```
访问地址: http://localhost:8443/uia/swagger-ui.html

**启动博客服务:** [详细配置](mcloud-blog/README.md)

```
cd mcloud-blog
mvn clean install
mvn spring-boot:run
```
访问地址: http://localhost:8081/swagger-ui.html

## 问题及建议

若是对于本项目有任何问题或建议,请提[Issue](https://github.com/heyuxian/mcloud/issues/new)。同时,如果你愿意参与开发,欢迎提PR.
若是对于本项目有任何问题或建议,请提[Issue](https://github.com/heyuxian/mcloud/issues/new

## License

Expand Down
4 changes: 2 additions & 2 deletions checks.xml → check-style-roles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@
<module name="Indentation">
<property name="basicOffset" value="4"/>
<property name="braceAdjustment" value="0"/>
<property name="caseIndent" value="2"/>
<property name="caseIndent" value="4"/>
<property name="throwsIndent" value="4"/>
<property name="lineWrappingIndentation" value="4"/>
<property name="arrayInitIndent" value="2"/>
<property name="arrayInitIndent" value="4"/>
</module>
<module name="AbbreviationAsWordInName">
<property name="ignoreFinal" value="false"/>
Expand Down
8 changes: 4 additions & 4 deletions code_style.xml → intellij-formatter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<package name="" withSubpackages="true" static="false" />
</value>
</option>
<option name="RIGHT_MARGIN" value="100" />
<option name="RIGHT_MARGIN" value="120" />
<option name="JD_ALIGN_PARAM_COMMENTS" value="false" />
<option name="JD_ALIGN_EXCEPTION_COMMENTS" value="false" />
<option name="JD_P_AT_EMPTY_LINES" value="false" />
Expand Down Expand Up @@ -132,15 +132,15 @@
<option name="FOR_BRACE_FORCE" value="3" />
<option name="PARENT_SETTINGS_INSTALLED" value="true" />
<indentOptions>
<option name="INDENT_SIZE" value="2" />
<option name="INDENT_SIZE" value="4" />
<option name="CONTINUATION_INDENT_SIZE" value="4" />
<option name="TAB_SIZE" value="2" />
<option name="TAB_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="JSON">
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
<option name="TAB_SIZE" value="2" />
<option name="TAB_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="JavaScript">
Expand Down
38 changes: 33 additions & 5 deletions mcloud-blog/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
# MCloud - 博客主服务
# MCloud - blog
## 简介

mcloud-blog 使用Spring cloud实现微服务架构的博客系统
以简单的博客系统作为 mcloud 的示例项目。

## 快速使用

**执行脚本**
**创建数据库**

运行项目根目录 `sql` 文件夹下的数据库脚本 `db_blog.sql`
```
CREATE DATABASE IF NOT EXISTS `db_blog` DEFAULT CHARACTER SET utf8;
```

**执行初始化脚本**

修改 flyway plugin 用户及密码:

mcloud-blog/pom.xml

```xml
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>4.2.0</version>
<configuration>
<user>root</user>
<password>root</password>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/db_blog</url>
</configuration>
</plugin>
```

在 mcloud-blog 根目录运行 maven 命令:

```
mvn flyway:clean flyway:migrate
```

**修改数据库用户及密码**

Expand All @@ -17,7 +45,7 @@ mcloud-blog 使用Spring cloud实现微服务架构的博客系统

refer: [统一认证服务](../mcloud-uia/README.md)

**启动博客服务**
**启动服务**

```
cd mcloud-blog
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.javaroad.blog.service;

import java.util.Objects;
import me.javaroad.blog.dto.request.ArticleRequest;
import me.javaroad.blog.dto.request.ArticleSearchRequest;
import me.javaroad.blog.dto.response.ArticlePageResponse;
Expand All @@ -15,6 +14,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Objects;

/**
* @author heyx
*/
Expand Down Expand Up @@ -47,7 +48,7 @@ Article getEntity(Long articleId) {

Article getNotNullEntity(Long articleId) {
Article article = getEntity(articleId);
if(Objects.isNull(article)) {
if (Objects.isNull(article)) {
throw new DataNotFoundException("article[id=%s] not found", articleId);
}
return article;
Expand All @@ -63,7 +64,7 @@ public ArticleResponse create(ArticleRequest articleRequest) {
@Transactional
public void delete(Long articleId) {
Article article = articleRepository.findOne(articleId);
if(Objects.isNull(article)) {
if (Objects.isNull(article)) {
throw new DataNotFoundException("article[id=%s] not found", articleId);
}
articleRepository.delete(article);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ User getEntity(Long userId) {
return userRepository.findOne(userId);
}

User getEntity(String username) {
return userRepository.findByUsername(username);
}

User getNotNullEntity(Long userId) {
User user = getEntity(userId);
if (Objects.isNull(user)) {
Expand All @@ -43,7 +47,4 @@ User getNotNullEntity(Long userId) {
return user;
}

User getEntity(String username) {
return userRepository.findByUsername(username);
}
}
1 change: 1 addition & 0 deletions mcloud-search/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# mcloud-search
2 changes: 1 addition & 1 deletion mcloud-uia/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mvn spring-boot:run

**预置用户**

- 用户名:user
- 用户名:mcloud-user
- 密码:123456

通过swagger调用登录接口即可获取 access_token 供其他服务使用.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
/**
* @author heyx
*/
public class UIAConstants {
public class UiaConstants {
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
@EnableEurekaClient
@SpringBootApplication
@EnableConfigurationProperties(OAuthProvider.class)
public class UIAServer {
public class UiaServer {

public static void main(String[] args) {
SpringApplication.run(UIAServer.class, args);
SpringApplication.run(UiaServer.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
@RestController
public class LoginApi {

private final OAuthApi oAuthApi;
private final OAuthApi oauthapi;
private final OAuthProvider provider;

@Autowired
public LoginApi(OAuthApi oAuthApi, OAuthProvider provider) {
this.oAuthApi = oAuthApi;
public LoginApi(OAuthApi oauthapi, OAuthProvider provider) {
this.oauthapi = oauthapi;
this.provider = provider;
}

Expand All @@ -37,7 +37,7 @@ public TokenInfo login(@RequestBody @Valid LoginRequest loginRequest) {
if (Objects.isNull(serverInfo)) {
throw new InvalidParameterException("invalid oauthProvider");
}
return oAuthApi.token(serverInfo, loginRequest);
return oauthapi.token(serverInfo, loginRequest);
}

@PostMapping("register")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@
public class LoginController {

private final OAuthProvider provider;
private final OAuthApi oAuthApi;
private final OAuthApi oauthapi;

@Autowired
public LoginController(OAuthProvider provider, OAuthApi oAuthApi) {
public LoginController(OAuthProvider provider, OAuthApi oauthapi) {
this.provider = provider;
this.oAuthApi = oAuthApi;
this.oauthapi = oauthapi;
}

@GetMapping("login")
public String login(String redirectUrl, @RequestParam(defaultValue = "mcloud") String oauthProvider, HttpServletRequest request) {
public String login(String redirectUrl, @RequestParam(defaultValue = "mcloud") String oauthProvider,
HttpServletRequest request) {
OAuthServerInfo serverInfo = provider.getProvider().get(oauthProvider);
if (Objects.isNull(serverInfo)) {
throw new InvalidParameterException("invalid oauthProvider");
Expand All @@ -45,7 +46,7 @@ public String callback(String code, String state, @RequestParam(defaultValue = "
if (Objects.isNull(serverInfo)) {
throw new InvalidParameterException("invalid oauthProvider");
}
TokenInfo token = oAuthApi.token(serverInfo, code);
TokenInfo token = oauthapi.token(serverInfo, code);

return "redirect:" + state + "#/login/success?token=" + token.getAccessToken();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
@AllArgsConstructor
@Builder
public class TokenInfo {

@JsonProperty("access_token")
private String accessToken;
@JsonProperty("refresh_token")
private String refresh_token;
@JsonProperty("refreshToken")
private String refreshToken;
@JsonProperty("expires_in")
private Long expiresIn;
private String scope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public TokenInfo token(OAuthServerInfo serverInfo, String code) {
private TokenInfo getTokenInfo(OAuthServerInfo serverInfo, String accessTokenUrl) {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("Authorization", serverInfo.buildBasicAuthString());
try{
try {
ResponseEntity<TokenInfo> responseEntity = restTemplate
.exchange(accessTokenUrl,
HttpMethod.POST,
Expand Down

0 comments on commit 3a28d53

Please sign in to comment.