();
30 | data.put("db.name", dbName);
31 | data.put("db.username", dbUsername);
32 | data.put("db.password", dbPassword);
33 | data.put("message1", message1);
34 | data.put("message2", message2);
35 |
36 | return data;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/spring-cloud-config-client/src/main/resources/bootstrap.properties:
--------------------------------------------------------------------------------
1 | #application name
2 | spring.application.name=ClientService
3 | #file name to get config
4 | spring.cloud.config.name=Service1,global
5 | # profile name
6 | spring.cloud.config.profile=default
7 |
8 | #Configuration server
9 | spring.cloud.config.uri=http://localhost:8000/
--------------------------------------------------------------------------------
/spring-cloud-config-server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning
7 | me.loda.spring
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-cloud-config-server
13 |
14 |
15 |
16 | org.springframework.cloud
17 | spring-cloud-config-server
18 | 2.0.4.RELEASE
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/spring-cloud-config-server/src/main/java/me/loda/spring/springcloudconfig/ConfigServer.java:
--------------------------------------------------------------------------------
1 | package me.loda.spring.springcloudconfig;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.config.server.EnableConfigServer;
6 |
7 | @EnableConfigServer
8 | @SpringBootApplication
9 | public class ConfigServer {
10 | public static void main(String[] args) {
11 | SpringApplication.run(ConfigServer.class, args);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-cloud-config-server/src/main/resources/bootstrap.properties:
--------------------------------------------------------------------------------
1 | #application name
2 | spring.application.name=vConfigServer
3 | #application port
4 | server.port=8000
5 |
6 | # make configuration files will be loaded from local
7 | spring.profiles.active=native
8 |
9 | # url contains config files on local
10 | spring.cloud.config.server.native.searchLocations=classpath:/config
--------------------------------------------------------------------------------
/spring-cloud-config-server/src/main/resources/config/Service1.properties:
--------------------------------------------------------------------------------
1 | server.port=8100
2 | message1=File-Service1
--------------------------------------------------------------------------------
/spring-cloud-config-server/src/main/resources/config/Service2.properties:
--------------------------------------------------------------------------------
1 | server.port=8200
2 | message2=File-Service2
--------------------------------------------------------------------------------
/spring-cloud-config-server/src/main/resources/config/global.properties:
--------------------------------------------------------------------------------
1 | db.name=Test
2 | db.username=atom
3 | db.password=ptit
4 |
--------------------------------------------------------------------------------
/spring-configuration-properties/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning
7 | me.loda.spring
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-configuration-properties
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-configuration-properties/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | loda:
2 | email: loda.namnh@gmail.com
3 | googleAnalyticsId: U-xxxxx
4 | authors:
5 | - loda
6 | - atom
7 | exampleMap:
8 | key1: hello
9 | key2: world
--------------------------------------------------------------------------------
/spring-redis/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning
7 | me.loda.spring
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-redis
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-data-jpa
18 |
19 |
20 |
21 | org.springframework.data
22 | spring-data-redis
23 |
24 |
25 |
26 | io.lettuce
27 | lettuce-core
28 | 5.1.3.RELEASE
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/spring-redis/src/main/java/me/loda/springredis/App.java:
--------------------------------------------------------------------------------
1 | package me.loda.springredis;
2 | /*******************************************************
3 | * For Vietnamese readers:
4 | * Các bạn thân mến, mình rất vui nếu project này giúp
5 | * ích được cho các bạn trong việc học tập và công việc. Nếu
6 | * bạn sử dụng lại toàn bộ hoặc một phần source code xin để
7 | * lại dường dẫn tới github hoặc tên tác giá.
8 | * Xin cảm ơn!
9 | *******************************************************/
10 |
11 | import org.springframework.boot.SpringApplication;
12 | import org.springframework.boot.autoconfigure.SpringBootApplication;
13 |
14 | /**
15 | * Copyright 2019 {@author Loda} (https://loda.me).
16 | * This project is licensed under the MIT license.
17 | *
18 | * @since 5/4/2019
19 | * Github: https://github.com/loda-kun
20 | */
21 | @SpringBootApplication
22 | public class App {
23 | public static void main(String[] args) {
24 | SpringApplication.run(App.class, args);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-redis/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | redis.host=localhost
2 | redis.port=6379
3 | server.port=8000
--------------------------------------------------------------------------------
/spring-security-example/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning
7 | me.loda.spring
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-security-example
13 |
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-security
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-thymeleaf
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/spring-security-example/src/main/java/me/loda/spring/springsecurity/App.java:
--------------------------------------------------------------------------------
1 | package me.loda.spring.springsecurity;
2 | /*******************************************************
3 | * For Vietnamese readers:
4 | * Các bạn thân mến, mình rất vui nếu project này giúp
5 | * ích được cho các bạn trong việc học tập và công việc. Nếu
6 | * bạn sử dụng lại toàn bộ hoặc một phần source code xin để
7 | * lại dường dẫn tới github hoặc tên tác giá.
8 | * Xin cảm ơn!
9 | *******************************************************/
10 |
11 | import org.springframework.boot.SpringApplication;
12 | import org.springframework.boot.autoconfigure.SpringBootApplication;
13 |
14 | /**
15 | * Copyright 2019 {@author Loda} (https://loda.me).
16 | * This project is licensed under the MIT license.
17 | *
18 | * @since 4/30/2019
19 | * Github: https://github.com/loda-kun
20 | */
21 | @SpringBootApplication
22 | public class App {
23 | public static void main(String[] args) {
24 | SpringApplication.run(App.class, args);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-security-example/src/main/java/me/loda/spring/springsecurity/WebController.java:
--------------------------------------------------------------------------------
1 | package me.loda.spring.springsecurity;
2 | /*******************************************************
3 | * For Vietnamese readers:
4 | * Các bạn thân mến, mình rất vui nếu project này giúp
5 | * ích được cho các bạn trong việc học tập và công việc. Nếu
6 | * bạn sử dụng lại toàn bộ hoặc một phần source code xin để
7 | * lại dường dẫn tới github hoặc tên tác giá.
8 | * Xin cảm ơn!
9 | *******************************************************/
10 |
11 | import org.springframework.stereotype.Controller;
12 | import org.springframework.web.bind.annotation.GetMapping;
13 |
14 | /**
15 | * Copyright 2019 {@author Loda} (https://loda.me).
16 | * This project is licensed under the MIT license.
17 | *
18 | * @since 4/30/2019
19 | * Github: https://github.com/loda-kun
20 | */
21 | @Controller
22 | public class WebController {
23 |
24 | @GetMapping(value = {"/", "/home"})
25 | public String homepage() {
26 | return "home";
27 | }
28 |
29 | @GetMapping("/hello")
30 | public String hello() {
31 | return "hello";
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/spring-security-example/src/main/resources/templates/hello.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Hello
5 |
6 |
7 | Chỉ những ai đăng nhập mới truy cập được trang này!
8 |
9 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/spring-security-example/src/main/resources/templates/home.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Spring Security Example
5 |
6 |
7 | Welcome!
8 |
9 | login
10 | Click here to see a loda homepage.
11 |
12 |
13 |
--------------------------------------------------------------------------------
/spring-security-hibernate-jwt/src/main/java/me/loda/springsecurityhibernatejwt/payload/LoginRequest.java:
--------------------------------------------------------------------------------
1 | package me.loda.springsecurityhibernatejwt.payload;
2 | /*******************************************************
3 | * For Vietnamese readers:
4 | * Các bạn thân mến, mình rất vui nếu project này giúp
5 | * ích được cho các bạn trong việc học tập và công việc. Nếu
6 | * bạn sử dụng lại toàn bộ hoặc một phần source code xin để
7 | * lại dường dẫn tới github hoặc tên tác giá.
8 | * Xin cảm ơn!
9 | *******************************************************/
10 |
11 | import javax.validation.constraints.NotBlank;
12 |
13 | import lombok.Data;
14 |
15 | /**
16 | * Copyright 2019 {@author Loda} (https://loda.me).
17 | * This project is licensed under the MIT license.
18 | *
19 | * @since 5/1/2019
20 | * Github: https://github.com/loda-kun
21 | */
22 | @Data
23 | public class LoginRequest {
24 | @NotBlank
25 | private String username;
26 |
27 | @NotBlank
28 | private String password;
29 | }
30 |
--------------------------------------------------------------------------------
/spring-security-hibernate-jwt/src/main/java/me/loda/springsecurityhibernatejwt/payload/LoginResponse.java:
--------------------------------------------------------------------------------
1 | package me.loda.springsecurityhibernatejwt.payload;
2 | /*******************************************************
3 | * For Vietnamese readers:
4 | * Các bạn thân mến, mình rất vui nếu project này giúp
5 | * ích được cho các bạn trong việc học tập và công việc. Nếu
6 | * bạn sử dụng lại toàn bộ hoặc một phần source code xin để
7 | * lại dường dẫn tới github hoặc tên tác giá.
8 | * Xin cảm ơn!
9 | *******************************************************/
10 |
11 | import lombok.Data;
12 |
13 | /**
14 | * Copyright 2019 {@author Loda} (https://loda.me).
15 | * This project is licensed under the MIT license.
16 | *
17 | * @since 5/1/2019
18 | * Github: https://github.com/loda-kun
19 | */
20 | @Data
21 | public class LoginResponse {
22 | private String accessToken;
23 | private String tokenType = "Bearer";
24 |
25 | public LoginResponse(String accessToken) {
26 | this.accessToken = accessToken;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/spring-security-hibernate-jwt/src/main/java/me/loda/springsecurityhibernatejwt/payload/RandomStuff.java:
--------------------------------------------------------------------------------
1 | package me.loda.springsecurityhibernatejwt.payload;
2 | /*******************************************************
3 | * For Vietnamese readers:
4 | * Các bạn thân mến, mình rất vui nếu project này giúp
5 | * ích được cho các bạn trong việc học tập và công việc. Nếu
6 | * bạn sử dụng lại toàn bộ hoặc một phần source code xin để
7 | * lại dường dẫn tới github hoặc tên tác giá.
8 | * Xin cảm ơn!
9 | *******************************************************/
10 |
11 | import lombok.AllArgsConstructor;
12 | import lombok.Data;
13 |
14 | /**
15 | * Copyright 2019 {@author Loda} (https://loda.me).
16 | * This project is licensed under the MIT license.
17 | *
18 | * @since 5/1/2019
19 | * Github: https://github.com/loda-kun
20 | */
21 | @Data
22 | @AllArgsConstructor
23 | public class RandomStuff {
24 | private String message;
25 | }
26 |
--------------------------------------------------------------------------------
/spring-security-hibernate-jwt/src/main/java/me/loda/springsecurityhibernatejwt/user/User.java:
--------------------------------------------------------------------------------
1 | package me.loda.springsecurityhibernatejwt.user;
2 | /*******************************************************
3 | * For Vietnamese readers:
4 | * Các bạn thân mến, mình rất vui nếu project này giúp
5 | * ích được cho các bạn trong việc học tập và công việc. Nếu
6 | * bạn sử dụng lại toàn bộ hoặc một phần source code xin để
7 | * lại dường dẫn tới github hoặc tên tác giá.
8 | * Xin cảm ơn!
9 | *******************************************************/
10 |
11 | import javax.persistence.Column;
12 | import javax.persistence.Entity;
13 | import javax.persistence.GeneratedValue;
14 | import javax.persistence.Id;
15 | import javax.persistence.Table;
16 |
17 | import lombok.Data;
18 |
19 | /**
20 | * Copyright 2019 {@author Loda} (https://loda.me).
21 | * This project is licensed under the MIT license.
22 | *
23 | * @since 4/30/2019
24 | * Github: https://github.com/loda-kun
25 | */
26 | @Entity
27 | @Table(name = "user")
28 | @Data
29 | public class User {
30 | @Id
31 | @GeneratedValue
32 | private Long id;
33 |
34 | @Column(nullable = false, unique = true)
35 | private String username;
36 | private String password;
37 | }
38 |
--------------------------------------------------------------------------------
/spring-security-hibernate-jwt/src/main/java/me/loda/springsecurityhibernatejwt/user/UserRepository.java:
--------------------------------------------------------------------------------
1 | package me.loda.springsecurityhibernatejwt.user;
2 | /*******************************************************
3 | * For Vietnamese readers:
4 | * Các bạn thân mến, mình rất vui nếu project này giúp
5 | * ích được cho các bạn trong việc học tập và công việc. Nếu
6 | * bạn sử dụng lại toàn bộ hoặc một phần source code xin để
7 | * lại dường dẫn tới github hoặc tên tác giá.
8 | * Xin cảm ơn!
9 | *******************************************************/
10 |
11 | import org.springframework.data.jpa.repository.JpaRepository;
12 | import org.springframework.stereotype.Repository;
13 |
14 | /**
15 | * Copyright 2019 {@author Loda} (https://loda.me).
16 | * This project is licensed under the MIT license.
17 | *
18 | * @since 4/30/2019
19 | * Github: https://github.com/loda-kun
20 | */
21 | @Repository
22 | public interface UserRepository extends JpaRepository {
23 | User findByUsername(String username);
24 | }
25 |
--------------------------------------------------------------------------------
/spring-security-hibernate/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning
7 | me.loda.spring
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-security-hibernate
13 |
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-security
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-thymeleaf
23 |
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-starter-data-jpa
28 |
29 |
30 |
31 | com.h2database
32 | h2
33 | runtime
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/spring-security-hibernate/src/main/java/me/loda/spring/springsecurityhibernate/WebController.java:
--------------------------------------------------------------------------------
1 | package me.loda.spring.springsecurityhibernate;
2 | /*******************************************************
3 | * For Vietnamese readers:
4 | * Các bạn thân mến, mình rất vui nếu project này giúp
5 | * ích được cho các bạn trong việc học tập và công việc. Nếu
6 | * bạn sử dụng lại toàn bộ hoặc một phần source code xin để
7 | * lại dường dẫn tới github hoặc tên tác giá.
8 | * Xin cảm ơn!
9 | *******************************************************/
10 |
11 | import org.springframework.stereotype.Controller;
12 | import org.springframework.web.bind.annotation.GetMapping;
13 |
14 | /**
15 | * Copyright 2019 {@author Loda} (https://loda.me).
16 | * This project is licensed under the MIT license.
17 | *
18 | * @since 4/30/2019
19 | * Github: https://github.com/loda-kun
20 | */
21 | @Controller
22 | public class WebController {
23 |
24 | @GetMapping(value = {"/", "/home"})
25 | public String homepage() {
26 | return "home";
27 | }
28 |
29 | @GetMapping("/hello")
30 | public String hello() {
31 | return "hello";
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/spring-security-hibernate/src/main/java/me/loda/spring/springsecurityhibernate/user/User.java:
--------------------------------------------------------------------------------
1 | package me.loda.spring.springsecurityhibernate.user;
2 | /*******************************************************
3 | * For Vietnamese readers:
4 | * Các bạn thân mến, mình rất vui nếu project này giúp
5 | * ích được cho các bạn trong việc học tập và công việc. Nếu
6 | * bạn sử dụng lại toàn bộ hoặc một phần source code xin để
7 | * lại dường dẫn tới github hoặc tên tác giá.
8 | * Xin cảm ơn!
9 | *******************************************************/
10 |
11 | import javax.persistence.Column;
12 | import javax.persistence.Entity;
13 | import javax.persistence.GeneratedValue;
14 | import javax.persistence.Id;
15 | import javax.persistence.Table;
16 |
17 | import lombok.Data;
18 |
19 | /**
20 | * Copyright 2019 {@author Loda} (https://loda.me).
21 | * This project is licensed under the MIT license.
22 | *
23 | * @since 4/30/2019
24 | * Github: https://github.com/loda-kun
25 | */
26 | @Entity
27 | @Table(name = "user")
28 | @Data
29 | public class User {
30 | @Id
31 | @GeneratedValue
32 | private Long id;
33 |
34 | @Column(nullable = false, unique = true)
35 | private String username;
36 | private String password;
37 | }
38 |
--------------------------------------------------------------------------------
/spring-security-hibernate/src/main/java/me/loda/spring/springsecurityhibernate/user/UserRepository.java:
--------------------------------------------------------------------------------
1 | package me.loda.spring.springsecurityhibernate.user;
2 | /*******************************************************
3 | * For Vietnamese readers:
4 | * Các bạn thân mến, mình rất vui nếu project này giúp
5 | * ích được cho các bạn trong việc học tập và công việc. Nếu
6 | * bạn sử dụng lại toàn bộ hoặc một phần source code xin để
7 | * lại dường dẫn tới github hoặc tên tác giá.
8 | * Xin cảm ơn!
9 | *******************************************************/
10 |
11 | import org.springframework.data.jpa.repository.JpaRepository;
12 | import org.springframework.stereotype.Repository;
13 |
14 | /**
15 | * Copyright 2019 {@author Loda} (https://loda.me).
16 | * This project is licensed under the MIT license.
17 | *
18 | * @since 4/30/2019
19 | * Github: https://github.com/loda-kun
20 | */
21 | @Repository
22 | public interface UserRepository extends JpaRepository {
23 | User findByUsername(String username);
24 | }
25 |
--------------------------------------------------------------------------------
/spring-security-hibernate/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=jdbc:h2:mem:testdb
2 | spring.datasource.driverClassName=org.h2.Driver
3 | spring.datasource.username=sa
4 | spring.datasource.password=
5 |
6 | spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
7 | # Enabling H2 Console
8 | spring.h2.console.enabled=true
--------------------------------------------------------------------------------
/spring-security-hibernate/src/main/resources/templates/hello.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Hello
5 |
6 |
7 | Chỉ những ai đăng nhập mới truy cập được trang này!
8 |
9 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/spring-security-hibernate/src/main/resources/templates/home.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Spring Security Example
5 |
6 |
7 | Welcome!
8 |
9 | login
10 | Click here to see a loda homepage.
11 |
12 |
13 |
--------------------------------------------------------------------------------
/test-mockito-basic/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning
7 | me.loda.spring
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | test-mockito-basic
13 |
14 |
15 |
--------------------------------------------------------------------------------
/test-mockito-basic/readme.md:
--------------------------------------------------------------------------------
1 | # Source
2 | Vào link để xem chi tiết có hình ảnh minh họa:
3 |
4 | [Loda.me - [Test] Hướng dẫn toàn tập Mockito][loda-link]
5 |
6 | [loda-link]: https://loda.me/test-huong-dan-toan-tap-mockito-loda1576641016810
7 |
8 | # Content without images
9 |
10 | ### Giới thiệu
--------------------------------------------------------------------------------
/test-mockito-basic/src/main/java/me/loda/springtest/App.java:
--------------------------------------------------------------------------------
1 | package me.loda.springtest;
2 |
3 | public class App {
4 | }
5 |
--------------------------------------------------------------------------------
/test-mockito-basic/src/test/java/me/loda/springtest/CaptorTest.java:
--------------------------------------------------------------------------------
1 | package me.loda.springtest;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 |
6 | import org.junit.Assert;
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 | import org.mockito.ArgumentCaptor;
10 | import org.mockito.Captor;
11 | import org.mockito.Mock;
12 | import org.mockito.Mockito;
13 | import org.mockito.junit.MockitoJUnitRunner;
14 |
15 | @RunWith(MockitoJUnitRunner.class)
16 | public class CaptorTest {
17 | @Mock
18 | List