Skip to content

Commit 85a5a6e

Browse files
authored
Merge pull request #11 from lvivJavaClub/hackster-config
Hackster & Refactoring
2 parents bb59c35 + eab7acf commit 85a5a6e

File tree

29 files changed

+478
-50
lines changed

29 files changed

+478
-50
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,20 @@ Sandbox to play with spring cloud features
2121

2222
# Dev
2323

24+
## Before
25+
26+
- Set up **JAVA_CLUB_SRC_HOME** environment variable that point to folder with project `spring-cloud`
27+
28+
- If you have issues with test containers (docker images) then check if you have `DOCKER_HOST` environment variable.
29+
If no then add it using this : `export DOCKER_HOST=unix:///var/run/docker.sock` (example for *Docker For Mac*)
30+
31+
2432
## Build
2533

2634
```bash
2735
mvn clean install
2836
```
2937

30-
**Notice** : if you have issues with test containers (docker images) then check if you have `DOCKER_HOST` environment variable.
31-
If no then add it using this : `export DOCKER_HOST=unix:///var/run/docker.sock` (example for *Docker For Mac*)
32-
3338
## Run
3439

3540
```bash

config-server/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<groupId>org.springframework.boot</groupId>
3131
<artifactId>spring-boot-starter-actuator</artifactId>
3232
</dependency>
33+
3334
<dependency>
3435
<groupId>org.springframework.cloud</groupId>
3536
<artifactId>spring-cloud-config-server</artifactId>
@@ -40,6 +41,11 @@
4041
<artifactId>spring-boot-starter-test</artifactId>
4142
<scope>test</scope>
4243
</dependency>
44+
45+
<dependency>
46+
<groupId>org.springframework.cloud</groupId>
47+
<artifactId>spring-cloud-starter-eureka</artifactId>
48+
</dependency>
4349
</dependencies>
4450

4551
<dependencyManagement>

config-server/src/main/java/com/lohika/jclub/ConfigserverApplication.java renamed to config-server/src/main/java/com/lohika/jclub/ConfigServerApplication.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
56
import org.springframework.cloud.config.server.EnableConfigServer;
67

8+
@EnableDiscoveryClient
79
@SpringBootApplication
810
@EnableConfigServer
9-
public class ConfigserverApplication {
10-
11-
public static void main(String[] args) {
12-
SpringApplication.run(ConfigserverApplication.class, args);
13-
}
11+
public class ConfigServerApplication {
12+
public static void main(String[] args) {
13+
SpringApplication.run(ConfigServerApplication.class, args);
14+
}
1415
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
spring.cloud.config.server.git.uri=${JAVA_CLUB_SRC_HOME}/spring-cloud
22
spring.cloud.config.server.git.search-paths=config
3-
server.port=8888
3+
4+
spring.cloud.config.discovery.enabled=true
5+
spring.application.name=config-server
6+
7+
server.port=8888

config-server/src/test/java/com/lohika/jclub/ConfigserverApplicationTests.java renamed to config-server/src/test/java/com/lohika/jclub/ConfigServerApplicationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
@RunWith(SpringRunner.class)
99
@SpringBootTest
10-
public class ConfigserverApplicationTests {
10+
public class ConfigServerApplicationTests {
1111

1212
@Test
1313
public void contextLoads() {

config/hackster-service.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
maxAllowedApartmentsPerRealtor=5

discovery-server/src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ spring.application.name=eureka-server
22
server.port=8761
33

44
eureka.client.register-with-eureka=false
5-
eureka.client.fetch-registry=false
5+
eureka.client.fetch-registry=false

hackster-service-client/pom.xml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.lohika.jclub.hackster.client</groupId>
8+
<artifactId>hackster-service-client</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
<packaging>jar</packaging>
11+
12+
<name>hackster-service-client</name>
13+
<description>Client library for Hackster Service</description>
14+
15+
<parent>
16+
<groupId>org.springframework.boot</groupId>
17+
<artifactId>spring-boot-starter-parent</artifactId>
18+
<version>1.5.4.RELEASE</version>
19+
<relativePath/> <!-- lookup parent from repository -->
20+
</parent>
21+
22+
<properties>
23+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
25+
<java.version>1.8</java.version>
26+
<spring-cloud.version>Dalston.RELEASE</spring-cloud.version>
27+
</properties>
28+
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.springframework.cloud</groupId>
32+
<artifactId>spring-cloud-starter-eureka</artifactId>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.springframework.cloud</groupId>
36+
<artifactId>spring-cloud-starter-feign</artifactId>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.springframework.cloud</groupId>
40+
<artifactId>spring-cloud-starter-hystrix</artifactId>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter-hateoas</artifactId>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>org.projectlombok</groupId>
49+
<artifactId>lombok</artifactId>
50+
<optional>true</optional>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>org.springframework.boot</groupId>
55+
<artifactId>spring-boot-starter-test</artifactId>
56+
<scope>test</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>com.lohika.jclub</groupId>
60+
<artifactId>discovery-server</artifactId>
61+
<version>0.0.1-SNAPSHOT</version>
62+
<scope>test</scope>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.testcontainers</groupId>
66+
<artifactId>testcontainers</artifactId>
67+
<version>1.3.0</version>
68+
<scope>test</scope>
69+
</dependency>
70+
<dependency>
71+
<groupId>com.lohika.jclub</groupId>
72+
<artifactId>hackster-service</artifactId>
73+
<version>0.0.1-SNAPSHOT</version>
74+
<scope>test</scope>
75+
</dependency>
76+
</dependencies>
77+
78+
<dependencyManagement>
79+
<dependencies>
80+
<dependency>
81+
<groupId>org.springframework.cloud</groupId>
82+
<artifactId>spring-cloud-dependencies</artifactId>
83+
<version>${spring-cloud.version}</version>
84+
<type>pom</type>
85+
<scope>import</scope>
86+
</dependency>
87+
</dependencies>
88+
</dependencyManagement>
89+
90+
</project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.lohika.jclub.hackster.client;
2+
3+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
4+
import org.springframework.cloud.netflix.feign.EnableFeignClients;
5+
import org.springframework.context.annotation.Import;
6+
import org.springframework.hateoas.config.EnableHypermediaSupport;
7+
8+
import java.lang.annotation.Documented;
9+
import java.lang.annotation.ElementType;
10+
import java.lang.annotation.Retention;
11+
import java.lang.annotation.RetentionPolicy;
12+
import java.lang.annotation.Target;
13+
14+
@Target(ElementType.TYPE)
15+
@Retention(RetentionPolicy.RUNTIME)
16+
@Documented
17+
18+
@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)
19+
@EnableFeignClients(clients = {HacksterServiceClient.class})
20+
@Import({FeignMappingDefaultConfiguration.class, HacksterServiceClientConfiguration.class})
21+
@EnableDiscoveryClient
22+
public @interface EnableHacksterServiceClient {
23+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.lohika.jclub.hackster.client;
2+
3+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
4+
import org.springframework.boot.autoconfigure.web.WebMvcRegistrations;
5+
import org.springframework.boot.autoconfigure.web.WebMvcRegistrationsAdapter;
6+
import org.springframework.cloud.netflix.feign.FeignClient;
7+
import org.springframework.context.annotation.Bean;
8+
import org.springframework.context.annotation.Configuration;
9+
import org.springframework.core.annotation.AnnotationUtils;
10+
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
11+
12+
import feign.Feign;
13+
14+
/**
15+
* https://github.com/spring-cloud/spring-cloud-netflix/issues/466
16+
*/
17+
@Configuration
18+
@ConditionalOnClass({Feign.class})
19+
public class FeignMappingDefaultConfiguration {
20+
@Bean
21+
public WebMvcRegistrations feignWebRegistrations() {
22+
return new WebMvcRegistrationsAdapter() {
23+
@Override
24+
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
25+
return new FeignFilterRequestMappingHandlerMapping();
26+
}
27+
};
28+
}
29+
30+
private static class FeignFilterRequestMappingHandlerMapping extends RequestMappingHandlerMapping {
31+
@Override
32+
protected boolean isHandler(Class<?> beanType) {
33+
return super.isHandler(beanType) && (AnnotationUtils.findAnnotation(beanType, FeignClient.class) == null);
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)