Skip to content

Commit 78a130b

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 91b1b3c + 2edb881 commit 78a130b

10 files changed

Lines changed: 140 additions & 19 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.constructordi;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.ComponentScan;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
import com.baeldung.constructordi.domain.Engine;
8+
import com.baeldung.constructordi.domain.Transmission;
9+
10+
@Configuration
11+
@ComponentScan("com.baeldung.constructordi")
12+
public class Config {
13+
14+
@Bean
15+
public Engine engine() {
16+
return new Engine("v8", 5);
17+
}
18+
19+
@Bean
20+
public Transmission transmission() {
21+
return new Transmission("sliding");
22+
}
23+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.baeldung.constructordi;
2+
3+
import org.springframework.context.ApplicationContext;
4+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5+
import org.springframework.context.support.ClassPathXmlApplicationContext;
6+
7+
import com.baeldung.constructordi.domain.Car;
8+
9+
public class SpringRunner {
10+
public static void main(String[] args) {
11+
Car toyota = getCarFromXml();
12+
13+
System.out.println(toyota);
14+
15+
toyota = getCarFromJavaConfig();
16+
17+
System.out.println(toyota);
18+
}
19+
20+
private static Car getCarFromJavaConfig() {
21+
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
22+
23+
return context.getBean(Car.class);
24+
}
25+
26+
private static Car getCarFromXml() {
27+
ApplicationContext context = new ClassPathXmlApplicationContext("baeldung.xml");
28+
29+
return context.getBean(Car.class);
30+
}
31+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.constructordi.domain;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.stereotype.Component;
5+
6+
@Component
7+
public class Car {
8+
private Engine engine;
9+
private Transmission transmission;
10+
11+
@Autowired
12+
public Car(Engine engine, Transmission transmission) {
13+
this.engine = engine;
14+
this.transmission = transmission;
15+
}
16+
17+
@Override
18+
public String toString() {
19+
return String.format("Engine: %s Transmission: %s", engine, transmission);
20+
}
21+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.constructordi.domain;
2+
3+
public class Engine {
4+
private String type;
5+
private int volume;
6+
7+
public Engine(String type, int volume) {
8+
this.type = type;
9+
this.volume = volume;
10+
}
11+
12+
@Override
13+
public String toString() {
14+
return String.format("%s %d", type, volume);
15+
}
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.constructordi.domain;
2+
3+
public class Transmission {
4+
private String type;
5+
6+
public Transmission(String type) {
7+
this.type = type;
8+
}
9+
10+
@Override
11+
public String toString() {
12+
return String.format("%s", type);
13+
}
14+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<beans xmlns="http://www.springframework.org/schema/beans"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://www.springframework.org/schema/beans
4+
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
5+
6+
<bean id="toyota" class="com.baeldung.constructordi.domain.Car">
7+
<constructor-arg index="0" ref="engine"/>
8+
<constructor-arg index="1" ref="transmission"/>
9+
</bean>
10+
11+
<bean id="engine" class="com.baeldung.constructordi.domain.Engine">
12+
<constructor-arg index="0" value="v4"/>
13+
<constructor-arg index="1" value="2"/>
14+
</bean>
15+
16+
<bean id="transmission" class="com.baeldung.constructordi.domain.Transmission">
17+
<constructor-arg value="sliding"/>
18+
</bean>
19+
20+
</beans>

‎spring-mvc-xml/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class RawDBDemoGeoIPLocationService{
1313
private DatabaseReader dbReader;
1414

1515
public RawDBDemoGeoIPLocationService() throws IOException {
16-
File database = new File("C:\\Users\\Parth Joshi\\Desktop\\GeoLite2-City.mmdb\\GeoLite2-City.mmdb");
16+
File database = new File("your-path-to-db-file");
1717
dbReader = new DatabaseReader.Builder(database).build();
1818
}
1919

‎spring-mvc-xml/src/main/webapp/GeoIpTest.jsp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@
7777
<div id="status"></div>
7878

7979
<div id="map" style="height: 500px; width:100%; position:absolute"></div>
80-
<!--AIzaSyDDr65sVtJtlbliOTAeXyZSDPvG9NROjJA -->
81-
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA4vsDQWHeOrDnzS98XMXl5hgwA9raaQZ8"
80+
81+
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR-MAPS-API-KEY"
8282
async defer></script>
8383
</body>
8484
</html>

‎spring-mvc-xml/src/test/java/com/baeldung/geoip/GeoIpIntegrationTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public class GeoIpIntegrationTest {
1515

1616
@Test
1717
public void givenIP_whenFetchingCity_thenReturnsCityData() throws IOException, GeoIp2Exception {
18-
File database = new File("C:\\Users\\Parth Joshi\\Desktop\\GeoLite2-City.mmdb\\GeoLite2-City.mmdb");
18+
File database = new File("your-path-to-db-file");
1919
DatabaseReader dbReader = new DatabaseReader.Builder(database).build();
2020

21-
InetAddress ipAddress = InetAddress.getByName("202.47.112.9");
21+
InetAddress ipAddress = InetAddress.getByName("your-public-ip");
2222
CityResponse response = dbReader.city(ipAddress);
2323

2424
String countryName = response.getCountry().getName();

‎spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package org.baeldung.okhttp;
22

3-
import okhttp3.*;
4-
import org.junit.Test;
3+
import static org.hamcrest.CoreMatchers.equalTo;
4+
import static org.junit.Assert.assertThat;
5+
import static org.junit.Assert.fail;
56

67
import java.io.IOException;
8+
79
import org.junit.Before;
810
import org.junit.Test;
11+
912
import okhttp3.Call;
1013
import okhttp3.Callback;
1114
import okhttp3.HttpUrl;
1215
import okhttp3.OkHttpClient;
1316
import okhttp3.Request;
1417
import okhttp3.Response;
1518

16-
1719
public class OkHttpGetLiveTest {
1820

1921
private static final String BASE_URL = "http://localhost:8080/spring-rest";
@@ -23,14 +25,12 @@ public class OkHttpGetLiveTest {
2325
@Before
2426
public void init() {
2527

26-
client = new OkHttpClient();
28+
client = new OkHttpClient();
2729
}
2830

2931
@Test
3032
public void whenGetRequest_thenCorrect() throws IOException {
31-
Request request = new Request.Builder()
32-
.url(BASE_URL + "/date")
33-
.build();
33+
Request request = new Request.Builder().url(BASE_URL + "/date").build();
3434

3535
Call call = client.newCall(request);
3636
Response response = call.execute();
@@ -45,9 +45,7 @@ public void whenGetRequestWithQueryParameter_thenCorrect() throws IOException {
4545

4646
String url = urlBuilder.build().toString();
4747

48-
Request request = new Request.Builder()
49-
.url(url)
50-
.build();
48+
Request request = new Request.Builder().url(url).build();
5149

5250
Call call = client.newCall(request);
5351
Response response = call.execute();
@@ -57,9 +55,7 @@ public void whenGetRequestWithQueryParameter_thenCorrect() throws IOException {
5755

5856
@Test
5957
public void whenAsynchronousGetRequest_thenCorrect() throws InterruptedException {
60-
Request request = new Request.Builder()
61-
.url(BASE_URL + "/date")
62-
.build();
58+
Request request = new Request.Builder().url(BASE_URL + "/date").build();
6359

6460
Call call = client.newCall(request);
6561

@@ -69,7 +65,7 @@ public void onResponse(Call call, Response response) throws IOException {
6965
}
7066

7167
public void onFailure(Call call, IOException e) {
72-
fail();
68+
fail();
7369
}
7470
});
7571

0 commit comments

Comments
 (0)