Skip to content

Commit

Permalink
adding examples for Chapter 4 & 5
Browse files Browse the repository at this point in the history
  • Loading branch information
dineshonjava committed Jul 7, 2017
1 parent 16f467f commit be980cd
Show file tree
Hide file tree
Showing 268 changed files with 6,158 additions and 3,046 deletions.
1,778 changes: 1,778 additions & 0 deletions .metadata/.log

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">

<context:annotation-config/>

<bean id="transferService" class="com.packt.patterninspring.chapter5.bankapp.service.TransferService">
<constructor-arg ref="accountRepository"/>
</bean>
<bean id="accountRepository" class="com.packt.patterninspring.chapter5.bankapp.repository.JdbcAccountRepository"/>
</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.packt.patterninspring.chapter5.bankapp.service;

import com.packt.patterninspring.chapter4.bankapp.repository.IAccountRepository;

/**
* @author Dinesh Rajput
*
*/
public class TransferService {

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.packt.patterninspring.chapter3.bankapp.config;
package com.packt.patterninspring.chapter5.bankapp.config;

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

/**
* @author Dinesh.Rajput
*
*/
@Configuration
@ComponentScan
@ComponentScan("com.packt.patterninspring.chapter5.bankapp")
public class AppConfig {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.packt.patterninspring.chapter5.bankapp.repository;

import org.springframework.stereotype.Repository;

import com.packt.patterninspring.chapter5.bankapp.model.Account;
import com.packt.patterninspring.chapter5.bankapp.model.Amount;
import com.packt.patterninspring.chapter5.bankapp.repository.AccountRepository;
@Repository
public class JdbcAccountRepository implements AccountRepository {

@Override
public Account findByAccountId(Long accountId) {
return new Account(accountId, "Arnav Rajput", new Amount(3000.0));
}

void populateCache(){
System.out.println("Called populateCache() method");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
*
*/
package com.doj.app.test;

import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.doj.app.bean.MyBean;

/**
* @author Dinesh.Rajput
*
*/
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
MyBean myBean = applicationContext.getBean(MyBean.class);
System.out.println(myBean.getName());
System.out.println("All registered Scopes are : ");
for(String scope : applicationContext.getBeanFactory().getRegisteredScopeNames()){
System.out.println(scope);
}
applicationContext.close();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.packt.patterninspring.chapter5.bankapp.repository;

import com.packt.patterninspring.chapter3.bankapp.model.Account;
import com.packt.patterninspring.chapter3.bankapp.model.Amount;

public interface TransferRepository {

void transfer(Account accountA, Account accountB, Amount amount);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
*
*/
package com.packt.patterninspring.chapter5.bankapp.bean;

/**
* @author Dinesh.Rajput
*
*/

public class MyBean {
String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.packt.patterninspring.chapter3.bankapp.repository;

import org.springframework.stereotype.Repository;

import com.packt.patterninspring.chapter3.bankapp.model.Account;
import com.packt.patterninspring.chapter3.bankapp.model.Amount;
import com.packt.patterninspring.chapter3.bankapp.repository.AccountRepository;
@Repository
public class JdbcAccountRepository implements AccountRepository {

@Override
public Account findByAccountId(Long accountId) {
return new Account(accountId, "Arnav Rajput", new Amount(3000.0));
}

}
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
/**
*
*/
package com.doj.app.service;

import org.springframework.stereotype.Service;
package com.packt.patterninspring.chapter4.bankapp.service;

import com.doj.app.repository.IAccountRepository;
import com.packt.patterninspring.chapter4.bankapp.repository.IAccountRepository;

/**
* @author Manzoor Alam
* @author Dinesh Rajput
*
*/
@Service("service")
public class TransferService {

IAccountRepository accountRepository;

public TransferService(IAccountRepository accountRepository){
this.accountRepository = accountRepository;
}

public void transfer(String accountA, String accountB, Double amount){
System.out.println("Amount has been tranferred");
}

public void setAccountRepository(IAccountRepository accountRepository) {
this.accountRepository = accountRepository;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.packt.patterninspring.chapter5.bankapp;

import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import com.packt.patterninspring.chapter5.bankapp.config.AppConfig;

/**
* @author Dinesh Rajput
*
*/
public class BeanLifeCycleDemo {

public static void main(String[] args) {
//ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(AppConfig.class);
applicationContext.close();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.packt.patterninspring.chapter5.bankapp.bpp;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
* @author Dinesh.Rajput
*
*/
public class MyBeanPostProcessor implements BeanPostProcessor {

@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
System.out.println("In After bean Initialization method. Bean name is "+beanName);
return bean;
}

public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
System.out.println("In Before bean Initialization method. Bean name is "+beanName);
return bean;
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.packt.patterninspring.chapter4.bankapp;

import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.packt.patterninspring.chapter5.bankapp.service.TransferService;

/**
* @author Dinesh Rajput
*
*/
public class FactoryBeanDemo {

public static void main(String[] args) {
ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
TransferService transferService = applicationContext.getBean(TransferService.class);
transferService.transfer("A", "B", 3000.1);
applicationContext.close();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">

<context:annotation-config/>

<bean id="transferService" class="com.packt.patterninspring.chapter5.bankapp.service.TransferService"/>
</bean>
<bean id="accountRepository" class="com.packt.patterninspring.chapter5.bankapp.repository.JdbcAccountRepository"/>
</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Chapter-05-Spring-Life-Cycle-Callback</groupId>
<artifactId>Chapter-05-Spring-Life-Cycle-Callback</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>config</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

This file was deleted.

Loading

0 comments on commit be980cd

Please sign in to comment.