Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions java8/src/test/java/com/unitbv/Java8Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,10 @@ public void getGetMapOfUsers(){
public void testGetPredicateForFilteringName(){
String name = "John";
Predicate<User> predicate = dataSource.getPredicateForFilteringByName(name);
List<User> expected = Stream.of(new User(1, "John", "Wick", 35, "actor"))
.collect(Collectors.toList());
List<User> expected = Stream.of(
new User(1, "John", "Wick", 35, "actor"),
new User(7, "Mark", "John", 17, "student")
).collect(Collectors.toList());
List<User> actual = dataSource.filterUsers(predicate);
Assertions.assertEquals(expected, actual);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@Service
public class FormatServiceConstructorInjection {
private final FormatUtil formatUtil;
private FormatUtil formatUtil;

public void checkFormatted() {
System.out.println(this.formatUtil.formatted(true));
Expand Down
4 changes: 2 additions & 2 deletions spring2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
Expand Down
20 changes: 20 additions & 0 deletions spring2/src/main/java/com/unitbv/dependsOn/AppConfig.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
package com.unitbv.dependsOn;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

@Configuration
@ComponentScan("com.unitbv.dependsOn")
public class AppConfig {

@Bean
@DependsOn("beanB")
public BeanA beana(){
return new BeanA();
}

@Bean
@DependsOn("beanC")
public BeanB beanB(){
return new BeanB();
}

@Bean
public BeanC beanC(){
return new BeanC();
}
}
3 changes: 3 additions & 0 deletions spring2/src/main/java/com/unitbv/dependsOn/BeanA.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package com.unitbv.dependsOn;

import org.springframework.stereotype.Component;

@Component
public class BeanA {
}
3 changes: 3 additions & 0 deletions spring2/src/main/java/com/unitbv/dependsOn/BeanB.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.unitbv.dependsOn;

import org.springframework.stereotype.Component;

@Component
public class BeanB {

}
3 changes: 3 additions & 0 deletions spring2/src/main/java/com/unitbv/dependsOn/BeanC.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package com.unitbv.dependsOn;

import org.springframework.stereotype.Component;

@Component
public class BeanC {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
package com.unitbv.events.configuration;

import com.unitbv.events.event.CarForRentEvent;
import com.unitbv.events.service.CarService;
import com.unitbv.events.service.PersonService;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AppConfig {
@Bean
public CarService carService(){
return new CarService();
}

@Bean
public PersonService personService(){
return new PersonService(new ApplicationEventPublisher() {
@Override
public void publishEvent(Object event) {
carService().addCarForRent((CarForRentEvent) event);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.unitbv.events.event;

import com.unitbv.events.model.Car;
import org.springframework.context.ApplicationEvent;

public class CarForRentEvent extends ApplicationEvent {
public CarForRentEvent(Object source) {
public CarForRentEvent(Car source) {
super(source);
}

public Car getCar(){
return (Car) source;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ public CarService() {
}

public void addCarForRent(CarForRentEvent carForRentEvent) {
this.availableCars.add(carForRentEvent.getCar());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.unitbv.events.service;

import com.unitbv.events.event.CarForRentEvent;
import com.unitbv.events.model.Car;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
Expand All @@ -16,5 +17,8 @@ public PersonService(ApplicationEventPublisher eventPublisher) {
public void rentCar(String model) {
final Car car = new Car(model);
//create a new event and publish car on event

CarForRentEvent carForRentEvent= new CarForRentEvent(car);
this.eventPublisher.publishEvent(carForRentEvent);
}
}
5 changes: 5 additions & 0 deletions spring2/src/main/java/com/unitbv/multipleConfigs/ConfigA.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.unitbv.multipleConfigs;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ConfigA {
@Bean
public BeanA beanA(){
return new BeanA();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.unitbv.multipleConfigs;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ConfigB {

@Bean
public BeanB beanB(){
return new BeanB();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.unitbv.multipleConfigs.appConfig;

import com.unitbv.multipleConfigs.ConfigA;
import com.unitbv.multipleConfigs.ConfigB;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan(basePackages = "com.unitbv.multipleConfigs.appConfig")
@Import({ConfigA.class, ConfigB.class})
public class AppConfig {

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.unitbv.profiles.automatically;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.*;

@Configuration
@ComponentScan
@ComponentScan("com.unitbv.profiles.automatically")
@PropertySource("classpath:profiles.properties")
public class AppConfig {
@Bean
@Profile("${spring.profile.active}")
public DevDataSourceConfig devDataSourceConfig()
{
return new DevDataSourceConfig();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.unitbv.profiles.automatically;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.unitbv.profiles.automatically;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Component
@Profile("prod")
public class ProdDataSourceConfig implements DataSourceConfig {
@Override
public void setup() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
package com.unitbv.profiles.programatically;

import org.springframework.context.annotation.*;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan("com.unitbv.profiles.programatically")
public class AppConfig {
@Bean
@Profile("dev")
public DevDataSourceConfig devDataSourceConfig(){
return new DevDataSourceConfig();
}

@Bean
@Profile("default")
public DevDataSourceConfig devDataSourceConfigDef(){
return new DevDataSourceConfig();
}

@Bean
@Profile("prod")
public ProdDataSourceConfig prodDataSourceConfig(){
return new ProdDataSourceConfig();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.unitbv.profiles.programatically;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Component
@Profile("dev")
public class DevDataSourceConfig implements DataSourceConfig {
@Override
public void setup() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.unitbv.profiles.programatically;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Component
@Profile("prod")
public class ProdDataSourceConfig implements DataSourceConfig {
@Override
public void setup() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package com.unitbv.profiles.stereotype;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.*;

@Configuration
@ComponentScan
@ComponentScan("com.unitbv.profiles.stereotype")
public class AppConfig {
@Bean
@Profile({"default","dev"})
public DevDataSourceConfig dataSourceConfig(){
return new DevDataSourceConfig();
}

@Bean
@Profile("prod")
public ProdDataSourceConfig prodDataSourceConfig(){
return new ProdDataSourceConfig();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.unitbv.profiles.stereotype;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Component
@Profile("dev")
public class DevDataSourceConfig implements DataSourceConfig {
@Override
public void setup() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.unitbv.profiles.stereotype;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Component
@Profile("prod")
public class ProdDataSourceConfig implements DataSourceConfig {
@Override
public void setup() {
Expand Down
10 changes: 10 additions & 0 deletions spring2/src/main/java/com/unitbv/properties/config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.PropertySource;

@Configuration
@RequiredArgsConstructor
@PropertySource("classpath:application.properties")
public class AppConfig {
@Value("${car.model}")
private String model;

@Bean
public Car car(){
return new Car(model);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
package com.unitbv.properties.programatically;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;

@Configuration
public class AppConfig {
@Value("${car.model}")
private String model;

@Bean
public Car car(){
return new Car(model);
}

@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
PropertySourcesPlaceholderConfigurer propConfigurer = new PropertySourcesPlaceholderConfigurer();
propConfigurer.setLocation(new ClassPathResource("application.properties"));
return propConfigurer;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.unitbv.properties.stereotype;

import org.springframework.context.annotation.Bean;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
Expand All @@ -8,4 +9,8 @@
@RequiredArgsConstructor
@ComponentScan
public class AppConfig {
@Bean
public Car car(){
return new Car();
}
}
Loading