SlideShare ist ein Scribd-Unternehmen logo
1 von 93
Spring Framework
Core
2st WEEK
30 Jun
GEEKY ACADEMY 2013
2 | GEEK ACADEMY 2013
INSTRUCTOR TEAM
SALAHPIYA
Salah (Dean) Chalermthai
Siam Chamnan Kit
SChalermthai@sprint3r.com
Piya (Tae) Lumyong
-
piya.tae@gmail.com
3 | GEEK ACADEMY 2013
Topic
• Introduction to Spring
• Basic bean
• IoC Container
• Bean Lifecycle
• Annotation
Introduction to Spring
GEEK ACADEMY 2013
5 | GEEK ACADEMY 2013
Introduction to Spring
• What's Spring
• Dependency Injection
• Module of Spring
• Usage scenarios
6 | GEEK ACADEMY 2013
What's Spring
• Goals
– make Enterprise Java easier to use
– promote good programming practice
– enabling a POJO-based programming model that is applicable in
a wide range of environments
• Some said Spring is just a “glue” for connecting all state of the art
technologies together (a.k.a Integration Framework) via it’s Application
Context.
• Heart and Soul of Spring is Dependency Injection and Aspect Oriented
Programming.
7 | GEEK ACADEMY 2013
What is Spring Framework today?
• an open source application framework
• a lightweight solution for enterprise applications
• non-invasive (POJO based)
• is modular
• extendible for other frameworks
• de facto standard of Java Enterprise Application
8 | GEEK ACADEMY 2013
Dependency Injection/Inversion of Control
9 | GEEK ACADEMY 2013
Dependency Injection/Inversion of Control
• ทั่วไป • DI
Hollywood Principle: "Don't call me, I'll call you."
10 | GEEK ACADEMY 2013
Module of Spring
11 | GEEK ACADEMY 2013
Full-fledged Spring web application
12 | GEEK ACADEMY 2013
Using a third-party web framework
13 | GEEK ACADEMY 2013
Remoting usage
14 | GEEK ACADEMY 2013
EJBs - Wrapping existing POJOs
15 | GEEK ACADEMY 2013
LAB1 Setup/Basic DI
16 | GEEK ACADEMY 2013
public interface MovieFinder {
public List<Movie> findMovie();
}
public class MovieLister {
private MovieFinder finder;
public MovieLister(MovieFinder finder) {
this.finder = finder;
}
public void listMovie() {
...
}
}
public class MovieFinderImpl2 implements MovieFinder {
private List<Movie> movies;
public MovieFinderImpl2(InputStream is) {
movies = new ArrayList<Movie>();
try {
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line=br.readLine())!=null) {
String[] csv = line.split("||");
movies.add(new Movie(csv[0], csv[1], Float.parseFloat(csv[2])));
}
} catch (IOException e) {}
}
@Override
public List<Movie> findMovie() {
return movies;
}
}
public class Assembler {
public static void main(String[] args) {
InputStream is = Assembler.class.getClass()
.getResourceAsStream("/movie.csv");
MovieFinder finder = new MovieFinderImpl2(is);
MovieLister lister = new MovieLister(finder);
lister.listMovie();
}
}
public class MovieListerTest {
@Test
public void testListMovie() {
//given
MovieFinder finder = mock(MovieFinder.class);
when(finder.findMovie()).thenReturn(new ArrayList<Movie>());
MovieLister lister = new MovieLister(finder);
//when
lister.listMovie();
//then
verify(finder).findMovie();
}
}
public class MovieFinderImpl2Test {
@Test
public void testFindMovie() {
//given
InputStream is = this.getClass().getResourceAsStream("/test-movie.csv");
MovieFinder finder = new MovieFinderImpl2(is);
//when
List<Movie> results = finder.findMovie();
//then
assertEquals(6, results.size());
}
}
LAB1 Setup/Basic DI
Basic Bean
GEEK ACADEMY 2013
18 | GEEK ACADEMY 2013
Basic bean
• What is bean?
• Creating bean
• Bean scope
• IoC Container
• Additional Features
• Bean Life cycle
19 | GEEK ACADEMY 2013
What is bean?
• The objects that form the backbone of your application and that
are managed by the Spring IoC container are called beans.
• A bean is an object that is instantiated, assembled, and
otherwise managed by a Spring IoC container.
• These beans are created with the configuration metadata that
you supply to the container, for example, in the form of XML
<bean/> definitions which you have already seen in previous
chapters.
20 | GEEK ACADEMY 2013
Creating bean
• Declaring a simple bean.
<bean id="hello" class="mypackage.HelloWorld" />
HelloWorld hello = new mypackage.HelloWorld();
21 | GEEK ACADEMY 2013
Creating bean
• Injecting through constructors.
<bean id="hello" class="mypackage.HelloWorld">
<constructor-arg value="Hello World" />
</bean>
HelloWorld hello = new mypackage.HelloWorld(“Hello World”);
22 | GEEK ACADEMY 2013
Creating bean
• Creating bean form factory.
<bean id="md5Digest"
class="java.security.MessageDigest"
factory-method="getInstance">
<constructor-arg value="MD5"/>
</bean>
MessageDigest md5Digest = new java.security.MessageDigest
.getInstance(“MD5”);
23 | GEEK ACADEMY 2013
Injecting into bean properties
• Injecting simple values.
<bean id="hello" class="mypackage.HelloWorld">
<property name=”message” value="Hello World" />
</bean>
HelloWorld hello = new mypackage.HelloWorld();
hello.setMessage(“Hello World”);
24 | GEEK ACADEMY 2013
Injecting into bean properties
• References to other beans (collaborators).
<bean id="msgService" class="mypackage.MessageService">
<property name=”messageProvider” ref="hello" />
</bean>
HelloWorld hello = …
MessageService msgService = new
mypackage.MessageService();
msgService.setMessageProvider(hello);
25 | GEEK ACADEMY 2013
Injecting into bean properties
• Inner beans
<bean id="outer" class="...">
<!-- instead of using a reference to a target bean, simply
define the target bean inline -->
<property name="target">
<!-- this is the inner bean -->
<bean class="com.mycompany.Person">
<property name="name" value="Fiona Apple"/>
<property name="age" value="25"/>
</bean>
</property>
</bean>
26 | GEEK ACADEMY 2013
Injecting into bean properties
• Collections
– java Collection type (List, Set, Map, and Properties)
– <list/>, <set/>, <map/>, <props/>
<list>
<value>
<bean … />
</value>
<ref bean="somebean" />
</list>
<props>
<prop key="admin">admin@company.org</prop>
<prop key="support">support@company.org</prop>
<prop key="develop">develop@company.org</prop>
</props>
27 | GEEK ACADEMY 2013
Injecting into bean properties
• Nulls
<property name=“target”>
<null />
</property>
28 | GEEK ACADEMY 2013
Injecting into bean properties
• p-namespace
– Using xml schema "http://www.springframework.org/schema/p"
<bean name="john-classic" class="com.mycompany.Person">
<property name="name" value="John Doe"/>
<property name="spouse" ref="jane"/>
</bean>
<bean name="john-modern"
class="com.mycompany.Person“
p:name="John Doe"
p:spouse-ref="jane"/>
29 | GEEK ACADEMY 2013
Injecting into bean properties
• Spring Expression Language – SpEL (v3.0)
<bean id="numberGuess" class="org.spring.samples.NumberGuess">
<property name="randomNumber" value="#{ T(java.lang.Math).random() * 100.0 }" />
<!-- other properties -->
</bean>
<bean id="shapeGuess" class="org.spring.samples.ShapeGuess">
<!-- refer to other bean properties by name -->
<property name="initialShapeSeed" value="#{ numberGuess.randomNumber }" />
<!-- other properties -->
</bean>
30 | GEEK ACADEMY 2013
Bean Scope
• Control bean creation in spring context.
• Default scope is singleton.
31 | GEEK ACADEMY 2013
Bean Scope
• Singleton scope
32 | GEEK ACADEMY 2013
Bean Scope
• Prototype scope
33 | GEEK ACADEMY 2013
Bean Scope
• Other scopes
– request, session, and global session are only used in
web-based applications.
• Custom scopes – Spring Framework Reference
IoC Container
GEEK ACADEMY 2013
35 | GEEK ACADEMY 2013
IoC Container
• Lightweight Container
• Application lifecycle
• Container Overview
• Configuration metadata
• Instantiating a container
36 | GEEK ACADEMY 2013
Lightweight Container
• Lifecycle management
• Lookup
• Configuration
• Dependency resolution
37 | GEEK ACADEMY 2013
Lightweight Container(Feature Added)
• Transaction
• Thread management
• Object pooling
• Clustering
• Management
• Remoting
• Exposing remote services
• Consuming remote services
• Customization and extensibility
• AOP
38 | GEEK ACADEMY 2013
Application lifecycle
39 | GEEK ACADEMY 2013
Container Overview
• Essence of IoC container
40 | GEEK ACADEMY 2013
Configuration metadata
• XML-based configuration metadata
• Annotation-based configuration metadata (v2.5)
– Java-based configuration (3.0) provided by Spring
JavaConfig project
41 | GEEK ACADEMY 2013
Configuration metadata
• XML-based configuration
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="..." class="...">
<!-- collaborators and configuration for this bean go here -->
</bean>
<bean id="..." class="...">
<!-- collaborators and configuration for this bean go here -->
</bean>
<!-- more bean definitions go here -->
</beans>
42 | GEEK ACADEMY 2013
Configuration metadata
• Java-based configuration (v3.0)
@Configuration
public class AppConfig {
@Bean
public MyService myService() {
return new MyServiceImpl();
}
}
<beans>
<bean id="myService" class="com.acme.services.MyServiceImpl"/>
</beans>
43 | GEEK ACADEMY 2013
Instantiating a container
• ApplicationContext represents the Spring IoC container
ApplicationContext context =
new ClassPathXmlApplicationContext(new String[] {"services.xml", "daos.xml"});
ApplicationContext ctx =
new AnnotationConfigApplicationContext(MyService.class, Dependency1.class, Dependency2.class);
GenericXmlApplicationContext context = new GenericXmlApplicationContext();
context.getEnvironment().setActiveProfiles("production", "no-jms");
context.load("spring-master.xml");
context.refresh();
44 | GEEK ACADEMY 2013
Using the container
// retrieve configured instance
PetStoreService service = context.getBean("petStore", PetStoreService.class);
// use configured instance
List userList = service.getUsernameList();
45 | GEEK ACADEMY 2013
Additional features
46 | GEEK ACADEMY 2013
Additional features
• Bean definition inheritance
• Importing configuration files
• Using depends-on
• Lazy-initialized beans
• Property Placeholder
47 | GEEK ACADEMY 2013
Bean definition inheritance
• Declaring parent and child beans
48 | GEEK ACADEMY 2013
Bean definition inheritance
<bean id="inheritedTestBeanWithoutClass" abstract="true">
<property name="name" value="parent"/>
<property name="age" value="1"/>
</bean>
<bean id="inheritsWithClass" class="org.springframework.beans.DerivedTestBean"
parent="inheritedTestBeanWithoutClass" init-method="initialize">
<property name="name" value="override"/>
<!-- age will inherit the value of 1 from the parent bean definition-->
</bean>
<bean id="inheritsWithClass2" class="org.springframework.beans.DerivedTestBean"
parent="inheritedTestBeanWithoutClass" init-method="initialize">
...
</bean>
<bean id="inheritsWithClass3" class="org.springframework.beans.DerivedTestBean"
parent="inheritedTestBeanWithoutClass" init-method="initialize">
...
</bean>
• Declaring parent and child beans
49 | GEEK ACADEMY 2013
Importing configuration files
• xml-context-config.xml
• xml-service-config.xml
• xml-repository-config.xml
<beans>
<import resource="classpath:xml-repository-config.xml"/>
<import resource="classpath:xml-service-config.xml"/>
</beans>
<beans>
<bean id="finder" class="mypackage.MovieFinder"/>
</beans>
<beans>
<bean id="lister" class="mypackage.MovieLister">
<constructor-arg ref="finder"/>
</bean>
</beans>
50 | GEEK ACADEMY 2013
Using depends-on
• Bean dependency
– one bean is set as a property of another
– accomplish this with the <ref/> element in XML-based
configuration metadata
– sometimes dependencies between beans are less direct
• For example, a static initializer in a class needs to be
triggered, such as database driver registration.
51 | GEEK ACADEMY 2013
Using depends-on
<bean id="beanOne" class="ExampleBean" >
<property name="manager" ref="manager" />
</bean>
<bean id="manager" class="ManagerBean" />
<bean id="beanOne" class="ExampleBean" depends-on="manager,accountDao">
<property name="manager" ref="manager" />
</bean>
<bean id="manager" class="ManagerBean" />
<bean id="accountDao" class="x.y.jdbc.JdbcAccountDao" />
• Direct Dependency
• Indirect Dependency
52 | GEEK ACADEMY 2013
Lazy-initialized beans
• IoC container create a bean instance when it is first requested
<bean id="lazy" class="ExpensiveToCreateBean" lazy-init="true"/>
53 | GEEK ACADEMY 2013
Property Placeholder
<context:property-placeholder location="classpath:com/foo/jdbc.properties"/>
<bean id="dataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
jdbc.driverClassName=org.hsqldb.jdbcDriver
jdbc.url=jdbc:hsqldb:hsql://production:9002
jdbc.username=sa
jdbc.password=root
54 | GEEK ACADEMY 2013
LAB2 Wiring Bean
55 | GEEK ACADEMY 2013
LAB2 Wiring Bean
MovieFinder
MovieFinderImpl2
MovieLister
CheckSum
Spring Container
Assembler
Bean Lifecycle
GEEK ACADEMY 2013
57 | GEEK ACADEMY 2013
Bean Lifecycle
• Bean Lifecycle
• Lifecycle Callback
• Bean Aware
• FactoryBean
• Extension Points
58 | GEEK ACADEMY 2013
Bean Life cycle
59 | GEEK ACADEMY 2013
Lifecycle Callback
• Implement Interface
– InitializingBean.afterPropertiesSet()
– DisposableBean.destroy()
• <bean/> element
– Init-method attribute
– destroy-method attribute
<bean id="exampleInitBean" class="examples.ExampleBean" init-method="init"/>
<bean id="exampleInitBean" class="examples.ExampleBean" destroy-method="cleanup"/>
@PostConstruct
@PreDestroy
Internally, the Spring Framework uses BeanPostProcessor implementations
to process any callback interfaces it can find and call the appropriate methods.
60 | GEEK ACADEMY 2013
Bean Aware
• Spring offers a range of Aware interfaces that
allow beans to indicate to the container that they
require a certain infrastructure dependency.
– ApplicationContextAware - Declaring ApplicationContext
– BeanFactoryAware - Declaring BeanFactory
– BeanNameAware - Name of the declaring bean
– ResourceLoaderAware - Configured loader for low-level access to resources
– ServletConfigAware - Current ServletConfig the container runs in. Valid only in a
web-aware Spring ApplicationContext
– ServletContextAware - Current ServletContext the container runs in. Valid only
in a web-aware Spring ApplicationContext
– Etc.
61 | GEEK ACADEMY 2013
Customizing instantiation logic with a FactoryBean
• FactoryBean interface is a point of pluggability into the Spring
IoC container's instantiation logic for complex initialization
bean.
public interface FactoryBean<T> {
/** Return an instance of the object managed by this factory. */
T getObject() throws Exception;
/** Return the type of object that this FactoryBean creates. */
Class<?> getObjectType();
/** Is the object managed by this factory a singleton? */
boolean isSingleton();
}
<bean id="bean" class="MyFactoryBean"/>
62 | GEEK ACADEMY 2013
Container Extension Points
• Container Extension Points – Spring Framework Reference
– BeanPostProcessor
• InitDestroyAnnotationBeanPostProcessor
• RequiredAnnotationBeanPostProcessor
– BeanFactoryPostProcessor
• PropertyPlaceholderConfigurer
• PropertyOverrideConfigurer
63 | GEEK ACADEMY 2013
Container Extension Points
• Becareful
– Note also that BeanPostProcessors registered programmatically are always processed before
those registered through auto-detection, regardless of any explicit ordering.
– Note that if you have beans wired into your BeanPostProcessor using autowiring or @Resource
(which may fall back to autowiring), Spring might access unexpected beans when searching for
type-matching dependency candidates, and therefore make them ineligible for auto-proxying or other
kinds of bean post-processing. For example, if you have a dependency annotated with @Resource where
the field/setter name does not directly correspond to the declared name of a bean and no name attribute
is used, then Spring will access other beans for matching them by type.
• This means that if you have @Transactional in a bean that is loaded in reference to a
BeanPostProcessor, that annotation is effectively ignored.
• The solution generally would be that if you need transactional behavior in a bean that has to
be loaded in reference to a BeanPostProcessor, you would need to use non-AOP transaction
definitions - i.e. use TransactionTemplate.
• Container Extension Points – Spring Framework Reference
64 | GEEK ACADEMY 2013
Forget It !!!
Annotation
GEEK ACADEMY 2013
66 | GEEK ACADEMY 2013
Annotation
• Annotation-based container configuration
• Classpath scanning and managed components
• Java-based container configuration
67 | GEEK ACADEMY 2013
Annotation-based container configuration
• Stereotypical
@Component
@Repository @Service @Controller @Configuration
Any Component
Data access Service classes Spring MVC Java Config
68 | GEEK ACADEMY 2013
Annotation-based container configuration
• Basic annotations (1)
– Spring Annotations
• @Autowired
• @Qualifier
• @Required
• @Value
– JSR 250 (Common Annotations for the
Java)
• @Resource
• @PostConstruct
• @PreDestroy
– JSR 330 (Dependency Injection for
Java)
• @Inject
• @Named
• @Scope
• @Singleton
• @Named
69 | GEEK ACADEMY 2013
Annotation-based container configuration
• Basic annotations (2)
– Spring Context
• @Scope
• @Bean
• @DependsOn
• @Lazy
– Transactional
• @Transactional
70 | GEEK ACADEMY 2013
@Value
@Component("ejbAccessService")
public class EjbAccessService {
/** The provider api connection url. */
@Value("${provider.api.url}")
private String apiUrl;
/** The provider api connection username. */
@Value("${provider.api.username}")
private String apiUsername;
/** The provider api connection password. */
@Value("${provider.api.password}")
private String apiPassword;
...
}
provider.api.url=corbaloc:iiop:localhost:2809
provider.api.username=Administrator
provider.api.password=password
<context:property-placeholder
location="classpath:META-INF/provider.properties"
properties-ref="providerProps" />
<util:properties id="providerProps">
<prop key="provider.api.url">t3://127.0.0.1:7001</prop>
<prop key="provider.api.username">weblogic</prop>
<prop key="provider.api.password">weblogic</prop>
</util:properties>
Properties
placeholders
71 | GEEK ACADEMY 2013
@Autowired (1)
@Service("accountService")
public class AccountServiceImpl {
@Autowired
private AccountRepository repository;
@Autowired
public AccountServiceImpl(AccountRepository repository) {}
@Autowired(required = false)
public void setRepository(AccountRepository repository) {}
@Autowired
public void populate(Repository r, OrderService s) {}
...
}
Matches by Type → Restricts by Qualifiers → Matches by Name
72 | GEEK ACADEMY 2013
@Autowired (2)
@Service
public class AccountServiceImpl {
@Autowired
private AccountRepository[] repositories;
@Autowired
public AccountServiceImpl(Set<AccountRepository> set) {}
@Autowired(required = false)
public void setRepositories(Map<String,AccountRepository> map){}
...
}
73 | GEEK ACADEMY 2013
@Required
public class AccountServiceImpl {
private AccountRepository repository;
@Required
public void setRepository(AccountRepository repository) {}
...
}
<bean name="accountService" class="AccountServiceImpl">
<property name="repository" ref="accountRepository"/>
</bean>
74 | GEEK ACADEMY 2013
@Qualifier
public class ReportServiceImpl {
@Autowired
@Qualifier("main")
private DataSource mainDataSource;
@Autowired
@Qualifier("freeDS")
private DataSource freeDataSource;
...
}
<beans>
<bean class="org.apache.commons.dbcp.BasicDataSource">
<qualifier value="main"/>
</bean>
<bean id="freeDS" class="org.apache.commons.dbcp.BasicDataSource"/>
...
</beans>
75 | GEEK ACADEMY 2013
@Scope
@Service
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class AccountServiceImpl implements AccountService {
...
}
76 | GEEK ACADEMY 2013
@Lazy & @DependsOn
@Lazy
@Service
@DependsOn({"orderService", "currencyService"})
public class AccountServiceImpl implements AccountService {
...
}
77 | GEEK ACADEMY 2013
Factory method component
@Component
public class CurrencyRepositoryFactory {
@Bean
@Lazy
@Scope("prototype")
@Qualifier("public")
public CurrencyRepository getCurrencyRepository() {
return new CurrencyMapRepository();
}
}
78 | GEEK ACADEMY 2013
JSR 250 @Resource
public class AccountServiceImpl {
@Resource(name = "orderService")
private OrderService orderService;
@Resource(name = "orderService")
public void setOrderService(OrderService orderService) {}
@Resource
private AuditService auditService;
@Resource
public void setAuditService(AuditService auditService) {}
...
}
If no name is specified explicitly, the default name is derived from the field name or setter method.
If no explicit name specified, and similar to @Autowired, @Resource finds a primary type match instead of a specific named bean.
Matches by Name → Matches by Type → Restricts by Qualifiers (ignored if match is found by name)
79 | GEEK ACADEMY 2013
Spring Annotation vs JSR-330
Spring JSR-330
@Autowired @Inject Has no 'required' attribute
@Component @Named
@Scope @Scope Only for meta-annotations and injection points
@Scope @Singleton Default scope is line 'prototype'
@Qualifier @Named
@Value X
@Required X
@Lazy X
80 | GEEK ACADEMY 2013
JSR 330
@Named
@Singleton
public class AccountServiceImpl implements AccountService {
@Inject
private AccountRepository repository;
@Inject
public AccountServiceImpl(@Named("default") AccountRepository r) {}
@Inject
public void setAccountRepository(AccountRepository repository) {}
...
}
@Inject Matches by Type → Restricts by Qualifiers → Matches by Name
81 | GEEK ACADEMY 2013
Classpath scanning and managed components
• Basic Configuration
<!-- looks for annotations on beans -->
<context:annotation-config/>
<!-- scan stereotyped classes and register BeanDefinition -->
<context:component-scan
base-package="org.bank.service,org.bank.repository">
82 | GEEK ACADEMY 2013
LAB3 Annotation-based
83 | GEEK ACADEMY 2013
Java-based container configuration
• Annotation-based configuration metadata
@Configuration
public class BankConfg {
@Bean
public TransferService createTransferService() {
return new TransferServiceImpl();
}
@Bean(name = "exchangeService", initMethod = "init")
public Exchange createExchangeService() {
return new ExchangeServiceImpl();
}
}
84 | GEEK ACADEMY 2013
Java-based container configuration
ApplicationContext context
= new AnnotationConfigApplicationContext(BankConfig.class);
• Instantiating a container
– Scanning
ApplicationContext context = new AnnotationConfigApplicationContext();
context.scan("org.bank.config");
context.refresh();
85 | GEEK ACADEMY 2013
@Import
@Configuration
@Import({RepositoryConfig.class, ServiceConfig.class})
public class BankConfig {
...
}
@Configuration
public class RepositoryConfg {
...
}
@Configuration
public class ServiceConfig {
...
}
86 | GEEK ACADEMY 2013
@ImportResources
@Configuration
@ImportResource("classpath:spring-master.xml")
public class BankConfig {
@Value("${jdbc.url}")
private String jdbcUrl;
@Bean
public DataSourse dataSource() {
return new SimpleDataSource(jdbcUrl);
}
}
jdbc.url=jdbc:derby://localhost:1527/test
jdbc.user=admin
jdbc.password=password
<context:property-placeholder
location="classpath:META-INF/jdbc.properties" />
Properties
placeholders
87 | GEEK ACADEMY 2013
Dependency injection
@Configuration
public class BankServiceConfig {
@Autowired
private CurrencyRepository currencyRepository;
@Bean
public CurrencyService currencyService() {
return new CurrencyServiceImpl(currencyRepository);
}
@Bean(name = {"orderBuilder", "builder"})
public OrderBuilder orderBuilder() {
return new OrderBuilder(currencyService());
}
}
88 | GEEK ACADEMY 2013
Approach to configuration
• XML
– infrastructure beans
• Annotations
– working beans
• Java
– an alternative to the FactoryBean
89 | GEEK ACADEMY 2013
LAB4 Java-based
90 | GEEK ACADEMY 2013
Links
• SpringSource
• Spring Reference 3.2
• Thank for
– Dmitry Noskov
91 | GEEK ACADEMY 2013
Books
GEEK ACADEMY 2013
THANK YOU FOR
YOUR TIME
GEEK ACADEMY 2013

Weitere ähnliche Inhalte

Was ist angesagt?

Spring boot
Spring bootSpring boot
Spring bootsdeeg
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action Alex Movila
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introductionRasheed Waraich
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot IntroductionJeevesh Pandey
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Hitesh-Java
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring FrameworkHùng Nguyễn Huy
 
Spring framework Introduction
Spring framework IntroductionSpring framework Introduction
Spring framework IntroductionAnuj Singh Rajput
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depthVinay Kumar
 
Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCFunnelll
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework tola99
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)slire
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 

Was ist angesagt? (20)

Spring boot
Spring bootSpring boot
Spring boot
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Spring jdbc
Spring jdbcSpring jdbc
Spring jdbc
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring framework Introduction
Spring framework IntroductionSpring framework Introduction
Spring framework Introduction
 
Java Spring Framework
Java Spring FrameworkJava Spring Framework
Java Spring Framework
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
 
Xke spring boot
Xke spring bootXke spring boot
Xke spring boot
 
Spring annotation
Spring annotationSpring annotation
Spring annotation
 
Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoC
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 

Andere mochten auch

Spring 4 final xtr_presentation
Spring 4 final xtr_presentationSpring 4 final xtr_presentation
Spring 4 final xtr_presentationsourabh aggarwal
 
Spring bean mod02
Spring bean mod02Spring bean mod02
Spring bean mod02Guo Albert
 
the Spring 4 update
the Spring 4 updatethe Spring 4 update
the Spring 4 updateJoshua Long
 
Getting Started with Spring Framework
Getting Started with Spring FrameworkGetting Started with Spring Framework
Getting Started with Spring FrameworkEdureka!
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring FrameworkDineesha Suraweera
 
Wicket - Brincando com Objetos
Wicket - Brincando com ObjetosWicket - Brincando com Objetos
Wicket - Brincando com ObjetosBruno Borges
 
Spring tutorial for beginners with examples
Spring tutorial for beginners with examplesSpring tutorial for beginners with examples
Spring tutorial for beginners with examplesinTwentyEight Minutes
 
nationalism movement in Indochina
nationalism movement in Indochina nationalism movement in Indochina
nationalism movement in Indochina madan kumar
 
Sectors of indian economy
Sectors of indian economySectors of indian economy
Sectors of indian economymadan kumar
 
Quartz: What is it?
Quartz: What is it?Quartz: What is it?
Quartz: What is it?alesialucy14
 
Physicalfeaturesofindia
Physicalfeaturesofindia Physicalfeaturesofindia
Physicalfeaturesofindia madan kumar
 
Java Classes methods and inheritance
Java Classes methods and inheritanceJava Classes methods and inheritance
Java Classes methods and inheritanceSrinivas Reddy
 
Getting Started with Spring Boot
Getting Started with Spring BootGetting Started with Spring Boot
Getting Started with Spring BootDavid Kiss
 
Apache Wicket @ JustJava 2008
Apache Wicket @ JustJava 2008Apache Wicket @ JustJava 2008
Apache Wicket @ JustJava 2008Bruno Borges
 
JDK 8, lambdas, streams, collectors - Bretagne Tour
JDK 8, lambdas, streams, collectors - Bretagne TourJDK 8, lambdas, streams, collectors - Bretagne Tour
JDK 8, lambdas, streams, collectors - Bretagne TourJosé Paumard
 
No more loops with lambdaj
No more loops with lambdajNo more loops with lambdaj
No more loops with lambdajMario Fusco
 

Andere mochten auch (20)

Spring 4 final xtr_presentation
Spring 4 final xtr_presentationSpring 4 final xtr_presentation
Spring 4 final xtr_presentation
 
Spring bean mod02
Spring bean mod02Spring bean mod02
Spring bean mod02
 
the Spring 4 update
the Spring 4 updatethe Spring 4 update
the Spring 4 update
 
Getting Started with Spring Framework
Getting Started with Spring FrameworkGetting Started with Spring Framework
Getting Started with Spring Framework
 
Spring 4 - A&BP CC
Spring 4 - A&BP CCSpring 4 - A&BP CC
Spring 4 - A&BP CC
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Wicket - Brincando com Objetos
Wicket - Brincando com ObjetosWicket - Brincando com Objetos
Wicket - Brincando com Objetos
 
Spring tutorial for beginners with examples
Spring tutorial for beginners with examplesSpring tutorial for beginners with examples
Spring tutorial for beginners with examples
 
Spring Framework Training Course
Spring Framework Training Course Spring Framework Training Course
Spring Framework Training Course
 
nationalism movement in Indochina
nationalism movement in Indochina nationalism movement in Indochina
nationalism movement in Indochina
 
Sectors of indian economy
Sectors of indian economySectors of indian economy
Sectors of indian economy
 
Quartz: What is it?
Quartz: What is it?Quartz: What is it?
Quartz: What is it?
 
Physicalfeaturesofindia
Physicalfeaturesofindia Physicalfeaturesofindia
Physicalfeaturesofindia
 
Spring 3 to 4
Spring 3 to 4Spring 3 to 4
Spring 3 to 4
 
Java Classes methods and inheritance
Java Classes methods and inheritanceJava Classes methods and inheritance
Java Classes methods and inheritance
 
Getting Started with Spring Boot
Getting Started with Spring BootGetting Started with Spring Boot
Getting Started with Spring Boot
 
Apache Wicket @ JustJava 2008
Apache Wicket @ JustJava 2008Apache Wicket @ JustJava 2008
Apache Wicket @ JustJava 2008
 
Introdução Wicket
Introdução WicketIntrodução Wicket
Introdução Wicket
 
JDK 8, lambdas, streams, collectors - Bretagne Tour
JDK 8, lambdas, streams, collectors - Bretagne TourJDK 8, lambdas, streams, collectors - Bretagne Tour
JDK 8, lambdas, streams, collectors - Bretagne Tour
 
No more loops with lambdaj
No more loops with lambdajNo more loops with lambdaj
No more loops with lambdaj
 

Ähnlich wie Spring framework core

Java EE 6 CDI Integrates with Spring & JSF
Java EE 6 CDI Integrates with Spring & JSFJava EE 6 CDI Integrates with Spring & JSF
Java EE 6 CDI Integrates with Spring & JSFJiayun Zhou
 
Spring andspringboot training
Spring andspringboot trainingSpring andspringboot training
Spring andspringboot trainingMallikarjuna G D
 
Make JSF more type-safe with CDI and MyFaces CODI
Make JSF more type-safe with CDI and MyFaces CODIMake JSF more type-safe with CDI and MyFaces CODI
Make JSF more type-safe with CDI and MyFaces CODIos890
 
2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdfDeoDuaNaoHet
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSCreating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSGunnar Hillert
 
Context and Dependency Injection
Context and Dependency InjectionContext and Dependency Injection
Context and Dependency InjectionWerner Keil
 
Introduction to Yii & performance comparison with Drupal
Introduction to Yii & performance comparison with DrupalIntroduction to Yii & performance comparison with Drupal
Introduction to Yii & performance comparison with Drupalcadet018
 
Working with AngularJS
Working with AngularJSWorking with AngularJS
Working with AngularJSAndré Vala
 
Apache DeltaSpike
Apache DeltaSpikeApache DeltaSpike
Apache DeltaSpikeos890
 
Spring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsugSpring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsugToshiaki Maki
 
Red Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
Red Hat JBoss BRMS and BPMS Workbench and Rich Client TechnologyRed Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
Red Hat JBoss BRMS and BPMS Workbench and Rich Client TechnologyMark Proctor
 
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6Saltmarch Media
 

Ähnlich wie Spring framework core (20)

Java EE 6 CDI Integrates with Spring & JSF
Java EE 6 CDI Integrates with Spring & JSFJava EE 6 CDI Integrates with Spring & JSF
Java EE 6 CDI Integrates with Spring & JSF
 
Spring andspringboot training
Spring andspringboot trainingSpring andspringboot training
Spring andspringboot training
 
Make JSF more type-safe with CDI and MyFaces CODI
Make JSF more type-safe with CDI and MyFaces CODIMake JSF more type-safe with CDI and MyFaces CODI
Make JSF more type-safe with CDI and MyFaces CODI
 
2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSCreating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJS
 
Context and Dependency Injection
Context and Dependency InjectionContext and Dependency Injection
Context and Dependency Injection
 
Apache DeltaSpike: The CDI Toolbox
Apache DeltaSpike: The CDI ToolboxApache DeltaSpike: The CDI Toolbox
Apache DeltaSpike: The CDI Toolbox
 
Apache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolboxApache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolbox
 
Codeinator
CodeinatorCodeinator
Codeinator
 
Introduction to Yii & performance comparison with Drupal
Introduction to Yii & performance comparison with DrupalIntroduction to Yii & performance comparison with Drupal
Introduction to Yii & performance comparison with Drupal
 
Working with AngularJS
Working with AngularJSWorking with AngularJS
Working with AngularJS
 
Liferay (DXP) 7 Tech Meetup for Developers
Liferay (DXP) 7 Tech Meetup for DevelopersLiferay (DXP) 7 Tech Meetup for Developers
Liferay (DXP) 7 Tech Meetup for Developers
 
Apache DeltaSpike
Apache DeltaSpikeApache DeltaSpike
Apache DeltaSpike
 
Spring framework aop
Spring framework aopSpring framework aop
Spring framework aop
 
Spring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsugSpring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsug
 
Red Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
Red Hat JBoss BRMS and BPMS Workbench and Rich Client TechnologyRed Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
Red Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
 
Spring
SpringSpring
Spring
 
Spring
SpringSpring
Spring
 
Spring
SpringSpring
Spring
 
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
 

Kürzlich hochgeladen

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 

Kürzlich hochgeladen (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

Spring framework core

  • 1. Spring Framework Core 2st WEEK 30 Jun GEEKY ACADEMY 2013
  • 2. 2 | GEEK ACADEMY 2013 INSTRUCTOR TEAM SALAHPIYA Salah (Dean) Chalermthai Siam Chamnan Kit SChalermthai@sprint3r.com Piya (Tae) Lumyong - piya.tae@gmail.com
  • 3. 3 | GEEK ACADEMY 2013 Topic • Introduction to Spring • Basic bean • IoC Container • Bean Lifecycle • Annotation
  • 5. 5 | GEEK ACADEMY 2013 Introduction to Spring • What's Spring • Dependency Injection • Module of Spring • Usage scenarios
  • 6. 6 | GEEK ACADEMY 2013 What's Spring • Goals – make Enterprise Java easier to use – promote good programming practice – enabling a POJO-based programming model that is applicable in a wide range of environments • Some said Spring is just a “glue” for connecting all state of the art technologies together (a.k.a Integration Framework) via it’s Application Context. • Heart and Soul of Spring is Dependency Injection and Aspect Oriented Programming.
  • 7. 7 | GEEK ACADEMY 2013 What is Spring Framework today? • an open source application framework • a lightweight solution for enterprise applications • non-invasive (POJO based) • is modular • extendible for other frameworks • de facto standard of Java Enterprise Application
  • 8. 8 | GEEK ACADEMY 2013 Dependency Injection/Inversion of Control
  • 9. 9 | GEEK ACADEMY 2013 Dependency Injection/Inversion of Control • ทั่วไป • DI Hollywood Principle: "Don't call me, I'll call you."
  • 10. 10 | GEEK ACADEMY 2013 Module of Spring
  • 11. 11 | GEEK ACADEMY 2013 Full-fledged Spring web application
  • 12. 12 | GEEK ACADEMY 2013 Using a third-party web framework
  • 13. 13 | GEEK ACADEMY 2013 Remoting usage
  • 14. 14 | GEEK ACADEMY 2013 EJBs - Wrapping existing POJOs
  • 15. 15 | GEEK ACADEMY 2013 LAB1 Setup/Basic DI
  • 16. 16 | GEEK ACADEMY 2013 public interface MovieFinder { public List<Movie> findMovie(); } public class MovieLister { private MovieFinder finder; public MovieLister(MovieFinder finder) { this.finder = finder; } public void listMovie() { ... } } public class MovieFinderImpl2 implements MovieFinder { private List<Movie> movies; public MovieFinderImpl2(InputStream is) { movies = new ArrayList<Movie>(); try { InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line; while ((line=br.readLine())!=null) { String[] csv = line.split("||"); movies.add(new Movie(csv[0], csv[1], Float.parseFloat(csv[2]))); } } catch (IOException e) {} } @Override public List<Movie> findMovie() { return movies; } } public class Assembler { public static void main(String[] args) { InputStream is = Assembler.class.getClass() .getResourceAsStream("/movie.csv"); MovieFinder finder = new MovieFinderImpl2(is); MovieLister lister = new MovieLister(finder); lister.listMovie(); } } public class MovieListerTest { @Test public void testListMovie() { //given MovieFinder finder = mock(MovieFinder.class); when(finder.findMovie()).thenReturn(new ArrayList<Movie>()); MovieLister lister = new MovieLister(finder); //when lister.listMovie(); //then verify(finder).findMovie(); } } public class MovieFinderImpl2Test { @Test public void testFindMovie() { //given InputStream is = this.getClass().getResourceAsStream("/test-movie.csv"); MovieFinder finder = new MovieFinderImpl2(is); //when List<Movie> results = finder.findMovie(); //then assertEquals(6, results.size()); } } LAB1 Setup/Basic DI
  • 18. 18 | GEEK ACADEMY 2013 Basic bean • What is bean? • Creating bean • Bean scope • IoC Container • Additional Features • Bean Life cycle
  • 19. 19 | GEEK ACADEMY 2013 What is bean? • The objects that form the backbone of your application and that are managed by the Spring IoC container are called beans. • A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. • These beans are created with the configuration metadata that you supply to the container, for example, in the form of XML <bean/> definitions which you have already seen in previous chapters.
  • 20. 20 | GEEK ACADEMY 2013 Creating bean • Declaring a simple bean. <bean id="hello" class="mypackage.HelloWorld" /> HelloWorld hello = new mypackage.HelloWorld();
  • 21. 21 | GEEK ACADEMY 2013 Creating bean • Injecting through constructors. <bean id="hello" class="mypackage.HelloWorld"> <constructor-arg value="Hello World" /> </bean> HelloWorld hello = new mypackage.HelloWorld(“Hello World”);
  • 22. 22 | GEEK ACADEMY 2013 Creating bean • Creating bean form factory. <bean id="md5Digest" class="java.security.MessageDigest" factory-method="getInstance"> <constructor-arg value="MD5"/> </bean> MessageDigest md5Digest = new java.security.MessageDigest .getInstance(“MD5”);
  • 23. 23 | GEEK ACADEMY 2013 Injecting into bean properties • Injecting simple values. <bean id="hello" class="mypackage.HelloWorld"> <property name=”message” value="Hello World" /> </bean> HelloWorld hello = new mypackage.HelloWorld(); hello.setMessage(“Hello World”);
  • 24. 24 | GEEK ACADEMY 2013 Injecting into bean properties • References to other beans (collaborators). <bean id="msgService" class="mypackage.MessageService"> <property name=”messageProvider” ref="hello" /> </bean> HelloWorld hello = … MessageService msgService = new mypackage.MessageService(); msgService.setMessageProvider(hello);
  • 25. 25 | GEEK ACADEMY 2013 Injecting into bean properties • Inner beans <bean id="outer" class="..."> <!-- instead of using a reference to a target bean, simply define the target bean inline --> <property name="target"> <!-- this is the inner bean --> <bean class="com.mycompany.Person"> <property name="name" value="Fiona Apple"/> <property name="age" value="25"/> </bean> </property> </bean>
  • 26. 26 | GEEK ACADEMY 2013 Injecting into bean properties • Collections – java Collection type (List, Set, Map, and Properties) – <list/>, <set/>, <map/>, <props/> <list> <value> <bean … /> </value> <ref bean="somebean" /> </list> <props> <prop key="admin">admin@company.org</prop> <prop key="support">support@company.org</prop> <prop key="develop">develop@company.org</prop> </props>
  • 27. 27 | GEEK ACADEMY 2013 Injecting into bean properties • Nulls <property name=“target”> <null /> </property>
  • 28. 28 | GEEK ACADEMY 2013 Injecting into bean properties • p-namespace – Using xml schema "http://www.springframework.org/schema/p" <bean name="john-classic" class="com.mycompany.Person"> <property name="name" value="John Doe"/> <property name="spouse" ref="jane"/> </bean> <bean name="john-modern" class="com.mycompany.Person“ p:name="John Doe" p:spouse-ref="jane"/>
  • 29. 29 | GEEK ACADEMY 2013 Injecting into bean properties • Spring Expression Language – SpEL (v3.0) <bean id="numberGuess" class="org.spring.samples.NumberGuess"> <property name="randomNumber" value="#{ T(java.lang.Math).random() * 100.0 }" /> <!-- other properties --> </bean> <bean id="shapeGuess" class="org.spring.samples.ShapeGuess"> <!-- refer to other bean properties by name --> <property name="initialShapeSeed" value="#{ numberGuess.randomNumber }" /> <!-- other properties --> </bean>
  • 30. 30 | GEEK ACADEMY 2013 Bean Scope • Control bean creation in spring context. • Default scope is singleton.
  • 31. 31 | GEEK ACADEMY 2013 Bean Scope • Singleton scope
  • 32. 32 | GEEK ACADEMY 2013 Bean Scope • Prototype scope
  • 33. 33 | GEEK ACADEMY 2013 Bean Scope • Other scopes – request, session, and global session are only used in web-based applications. • Custom scopes – Spring Framework Reference
  • 35. 35 | GEEK ACADEMY 2013 IoC Container • Lightweight Container • Application lifecycle • Container Overview • Configuration metadata • Instantiating a container
  • 36. 36 | GEEK ACADEMY 2013 Lightweight Container • Lifecycle management • Lookup • Configuration • Dependency resolution
  • 37. 37 | GEEK ACADEMY 2013 Lightweight Container(Feature Added) • Transaction • Thread management • Object pooling • Clustering • Management • Remoting • Exposing remote services • Consuming remote services • Customization and extensibility • AOP
  • 38. 38 | GEEK ACADEMY 2013 Application lifecycle
  • 39. 39 | GEEK ACADEMY 2013 Container Overview • Essence of IoC container
  • 40. 40 | GEEK ACADEMY 2013 Configuration metadata • XML-based configuration metadata • Annotation-based configuration metadata (v2.5) – Java-based configuration (3.0) provided by Spring JavaConfig project
  • 41. 41 | GEEK ACADEMY 2013 Configuration metadata • XML-based configuration <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="..." class="..."> <!-- collaborators and configuration for this bean go here --> </bean> <bean id="..." class="..."> <!-- collaborators and configuration for this bean go here --> </bean> <!-- more bean definitions go here --> </beans>
  • 42. 42 | GEEK ACADEMY 2013 Configuration metadata • Java-based configuration (v3.0) @Configuration public class AppConfig { @Bean public MyService myService() { return new MyServiceImpl(); } } <beans> <bean id="myService" class="com.acme.services.MyServiceImpl"/> </beans>
  • 43. 43 | GEEK ACADEMY 2013 Instantiating a container • ApplicationContext represents the Spring IoC container ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"services.xml", "daos.xml"}); ApplicationContext ctx = new AnnotationConfigApplicationContext(MyService.class, Dependency1.class, Dependency2.class); GenericXmlApplicationContext context = new GenericXmlApplicationContext(); context.getEnvironment().setActiveProfiles("production", "no-jms"); context.load("spring-master.xml"); context.refresh();
  • 44. 44 | GEEK ACADEMY 2013 Using the container // retrieve configured instance PetStoreService service = context.getBean("petStore", PetStoreService.class); // use configured instance List userList = service.getUsernameList();
  • 45. 45 | GEEK ACADEMY 2013 Additional features
  • 46. 46 | GEEK ACADEMY 2013 Additional features • Bean definition inheritance • Importing configuration files • Using depends-on • Lazy-initialized beans • Property Placeholder
  • 47. 47 | GEEK ACADEMY 2013 Bean definition inheritance • Declaring parent and child beans
  • 48. 48 | GEEK ACADEMY 2013 Bean definition inheritance <bean id="inheritedTestBeanWithoutClass" abstract="true"> <property name="name" value="parent"/> <property name="age" value="1"/> </bean> <bean id="inheritsWithClass" class="org.springframework.beans.DerivedTestBean" parent="inheritedTestBeanWithoutClass" init-method="initialize"> <property name="name" value="override"/> <!-- age will inherit the value of 1 from the parent bean definition--> </bean> <bean id="inheritsWithClass2" class="org.springframework.beans.DerivedTestBean" parent="inheritedTestBeanWithoutClass" init-method="initialize"> ... </bean> <bean id="inheritsWithClass3" class="org.springframework.beans.DerivedTestBean" parent="inheritedTestBeanWithoutClass" init-method="initialize"> ... </bean> • Declaring parent and child beans
  • 49. 49 | GEEK ACADEMY 2013 Importing configuration files • xml-context-config.xml • xml-service-config.xml • xml-repository-config.xml <beans> <import resource="classpath:xml-repository-config.xml"/> <import resource="classpath:xml-service-config.xml"/> </beans> <beans> <bean id="finder" class="mypackage.MovieFinder"/> </beans> <beans> <bean id="lister" class="mypackage.MovieLister"> <constructor-arg ref="finder"/> </bean> </beans>
  • 50. 50 | GEEK ACADEMY 2013 Using depends-on • Bean dependency – one bean is set as a property of another – accomplish this with the <ref/> element in XML-based configuration metadata – sometimes dependencies between beans are less direct • For example, a static initializer in a class needs to be triggered, such as database driver registration.
  • 51. 51 | GEEK ACADEMY 2013 Using depends-on <bean id="beanOne" class="ExampleBean" > <property name="manager" ref="manager" /> </bean> <bean id="manager" class="ManagerBean" /> <bean id="beanOne" class="ExampleBean" depends-on="manager,accountDao"> <property name="manager" ref="manager" /> </bean> <bean id="manager" class="ManagerBean" /> <bean id="accountDao" class="x.y.jdbc.JdbcAccountDao" /> • Direct Dependency • Indirect Dependency
  • 52. 52 | GEEK ACADEMY 2013 Lazy-initialized beans • IoC container create a bean instance when it is first requested <bean id="lazy" class="ExpensiveToCreateBean" lazy-init="true"/>
  • 53. 53 | GEEK ACADEMY 2013 Property Placeholder <context:property-placeholder location="classpath:com/foo/jdbc.properties"/> <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="${jdbc.driverClassName}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </bean> jdbc.driverClassName=org.hsqldb.jdbcDriver jdbc.url=jdbc:hsqldb:hsql://production:9002 jdbc.username=sa jdbc.password=root
  • 54. 54 | GEEK ACADEMY 2013 LAB2 Wiring Bean
  • 55. 55 | GEEK ACADEMY 2013 LAB2 Wiring Bean MovieFinder MovieFinderImpl2 MovieLister CheckSum Spring Container Assembler
  • 57. 57 | GEEK ACADEMY 2013 Bean Lifecycle • Bean Lifecycle • Lifecycle Callback • Bean Aware • FactoryBean • Extension Points
  • 58. 58 | GEEK ACADEMY 2013 Bean Life cycle
  • 59. 59 | GEEK ACADEMY 2013 Lifecycle Callback • Implement Interface – InitializingBean.afterPropertiesSet() – DisposableBean.destroy() • <bean/> element – Init-method attribute – destroy-method attribute <bean id="exampleInitBean" class="examples.ExampleBean" init-method="init"/> <bean id="exampleInitBean" class="examples.ExampleBean" destroy-method="cleanup"/> @PostConstruct @PreDestroy Internally, the Spring Framework uses BeanPostProcessor implementations to process any callback interfaces it can find and call the appropriate methods.
  • 60. 60 | GEEK ACADEMY 2013 Bean Aware • Spring offers a range of Aware interfaces that allow beans to indicate to the container that they require a certain infrastructure dependency. – ApplicationContextAware - Declaring ApplicationContext – BeanFactoryAware - Declaring BeanFactory – BeanNameAware - Name of the declaring bean – ResourceLoaderAware - Configured loader for low-level access to resources – ServletConfigAware - Current ServletConfig the container runs in. Valid only in a web-aware Spring ApplicationContext – ServletContextAware - Current ServletContext the container runs in. Valid only in a web-aware Spring ApplicationContext – Etc.
  • 61. 61 | GEEK ACADEMY 2013 Customizing instantiation logic with a FactoryBean • FactoryBean interface is a point of pluggability into the Spring IoC container's instantiation logic for complex initialization bean. public interface FactoryBean<T> { /** Return an instance of the object managed by this factory. */ T getObject() throws Exception; /** Return the type of object that this FactoryBean creates. */ Class<?> getObjectType(); /** Is the object managed by this factory a singleton? */ boolean isSingleton(); } <bean id="bean" class="MyFactoryBean"/>
  • 62. 62 | GEEK ACADEMY 2013 Container Extension Points • Container Extension Points – Spring Framework Reference – BeanPostProcessor • InitDestroyAnnotationBeanPostProcessor • RequiredAnnotationBeanPostProcessor – BeanFactoryPostProcessor • PropertyPlaceholderConfigurer • PropertyOverrideConfigurer
  • 63. 63 | GEEK ACADEMY 2013 Container Extension Points • Becareful – Note also that BeanPostProcessors registered programmatically are always processed before those registered through auto-detection, regardless of any explicit ordering. – Note that if you have beans wired into your BeanPostProcessor using autowiring or @Resource (which may fall back to autowiring), Spring might access unexpected beans when searching for type-matching dependency candidates, and therefore make them ineligible for auto-proxying or other kinds of bean post-processing. For example, if you have a dependency annotated with @Resource where the field/setter name does not directly correspond to the declared name of a bean and no name attribute is used, then Spring will access other beans for matching them by type. • This means that if you have @Transactional in a bean that is loaded in reference to a BeanPostProcessor, that annotation is effectively ignored. • The solution generally would be that if you need transactional behavior in a bean that has to be loaded in reference to a BeanPostProcessor, you would need to use non-AOP transaction definitions - i.e. use TransactionTemplate. • Container Extension Points – Spring Framework Reference
  • 64. 64 | GEEK ACADEMY 2013 Forget It !!!
  • 66. 66 | GEEK ACADEMY 2013 Annotation • Annotation-based container configuration • Classpath scanning and managed components • Java-based container configuration
  • 67. 67 | GEEK ACADEMY 2013 Annotation-based container configuration • Stereotypical @Component @Repository @Service @Controller @Configuration Any Component Data access Service classes Spring MVC Java Config
  • 68. 68 | GEEK ACADEMY 2013 Annotation-based container configuration • Basic annotations (1) – Spring Annotations • @Autowired • @Qualifier • @Required • @Value – JSR 250 (Common Annotations for the Java) • @Resource • @PostConstruct • @PreDestroy – JSR 330 (Dependency Injection for Java) • @Inject • @Named • @Scope • @Singleton • @Named
  • 69. 69 | GEEK ACADEMY 2013 Annotation-based container configuration • Basic annotations (2) – Spring Context • @Scope • @Bean • @DependsOn • @Lazy – Transactional • @Transactional
  • 70. 70 | GEEK ACADEMY 2013 @Value @Component("ejbAccessService") public class EjbAccessService { /** The provider api connection url. */ @Value("${provider.api.url}") private String apiUrl; /** The provider api connection username. */ @Value("${provider.api.username}") private String apiUsername; /** The provider api connection password. */ @Value("${provider.api.password}") private String apiPassword; ... } provider.api.url=corbaloc:iiop:localhost:2809 provider.api.username=Administrator provider.api.password=password <context:property-placeholder location="classpath:META-INF/provider.properties" properties-ref="providerProps" /> <util:properties id="providerProps"> <prop key="provider.api.url">t3://127.0.0.1:7001</prop> <prop key="provider.api.username">weblogic</prop> <prop key="provider.api.password">weblogic</prop> </util:properties> Properties placeholders
  • 71. 71 | GEEK ACADEMY 2013 @Autowired (1) @Service("accountService") public class AccountServiceImpl { @Autowired private AccountRepository repository; @Autowired public AccountServiceImpl(AccountRepository repository) {} @Autowired(required = false) public void setRepository(AccountRepository repository) {} @Autowired public void populate(Repository r, OrderService s) {} ... } Matches by Type → Restricts by Qualifiers → Matches by Name
  • 72. 72 | GEEK ACADEMY 2013 @Autowired (2) @Service public class AccountServiceImpl { @Autowired private AccountRepository[] repositories; @Autowired public AccountServiceImpl(Set<AccountRepository> set) {} @Autowired(required = false) public void setRepositories(Map<String,AccountRepository> map){} ... }
  • 73. 73 | GEEK ACADEMY 2013 @Required public class AccountServiceImpl { private AccountRepository repository; @Required public void setRepository(AccountRepository repository) {} ... } <bean name="accountService" class="AccountServiceImpl"> <property name="repository" ref="accountRepository"/> </bean>
  • 74. 74 | GEEK ACADEMY 2013 @Qualifier public class ReportServiceImpl { @Autowired @Qualifier("main") private DataSource mainDataSource; @Autowired @Qualifier("freeDS") private DataSource freeDataSource; ... } <beans> <bean class="org.apache.commons.dbcp.BasicDataSource"> <qualifier value="main"/> </bean> <bean id="freeDS" class="org.apache.commons.dbcp.BasicDataSource"/> ... </beans>
  • 75. 75 | GEEK ACADEMY 2013 @Scope @Service @Scope(BeanDefinition.SCOPE_PROTOTYPE) public class AccountServiceImpl implements AccountService { ... }
  • 76. 76 | GEEK ACADEMY 2013 @Lazy & @DependsOn @Lazy @Service @DependsOn({"orderService", "currencyService"}) public class AccountServiceImpl implements AccountService { ... }
  • 77. 77 | GEEK ACADEMY 2013 Factory method component @Component public class CurrencyRepositoryFactory { @Bean @Lazy @Scope("prototype") @Qualifier("public") public CurrencyRepository getCurrencyRepository() { return new CurrencyMapRepository(); } }
  • 78. 78 | GEEK ACADEMY 2013 JSR 250 @Resource public class AccountServiceImpl { @Resource(name = "orderService") private OrderService orderService; @Resource(name = "orderService") public void setOrderService(OrderService orderService) {} @Resource private AuditService auditService; @Resource public void setAuditService(AuditService auditService) {} ... } If no name is specified explicitly, the default name is derived from the field name or setter method. If no explicit name specified, and similar to @Autowired, @Resource finds a primary type match instead of a specific named bean. Matches by Name → Matches by Type → Restricts by Qualifiers (ignored if match is found by name)
  • 79. 79 | GEEK ACADEMY 2013 Spring Annotation vs JSR-330 Spring JSR-330 @Autowired @Inject Has no 'required' attribute @Component @Named @Scope @Scope Only for meta-annotations and injection points @Scope @Singleton Default scope is line 'prototype' @Qualifier @Named @Value X @Required X @Lazy X
  • 80. 80 | GEEK ACADEMY 2013 JSR 330 @Named @Singleton public class AccountServiceImpl implements AccountService { @Inject private AccountRepository repository; @Inject public AccountServiceImpl(@Named("default") AccountRepository r) {} @Inject public void setAccountRepository(AccountRepository repository) {} ... } @Inject Matches by Type → Restricts by Qualifiers → Matches by Name
  • 81. 81 | GEEK ACADEMY 2013 Classpath scanning and managed components • Basic Configuration <!-- looks for annotations on beans --> <context:annotation-config/> <!-- scan stereotyped classes and register BeanDefinition --> <context:component-scan base-package="org.bank.service,org.bank.repository">
  • 82. 82 | GEEK ACADEMY 2013 LAB3 Annotation-based
  • 83. 83 | GEEK ACADEMY 2013 Java-based container configuration • Annotation-based configuration metadata @Configuration public class BankConfg { @Bean public TransferService createTransferService() { return new TransferServiceImpl(); } @Bean(name = "exchangeService", initMethod = "init") public Exchange createExchangeService() { return new ExchangeServiceImpl(); } }
  • 84. 84 | GEEK ACADEMY 2013 Java-based container configuration ApplicationContext context = new AnnotationConfigApplicationContext(BankConfig.class); • Instantiating a container – Scanning ApplicationContext context = new AnnotationConfigApplicationContext(); context.scan("org.bank.config"); context.refresh();
  • 85. 85 | GEEK ACADEMY 2013 @Import @Configuration @Import({RepositoryConfig.class, ServiceConfig.class}) public class BankConfig { ... } @Configuration public class RepositoryConfg { ... } @Configuration public class ServiceConfig { ... }
  • 86. 86 | GEEK ACADEMY 2013 @ImportResources @Configuration @ImportResource("classpath:spring-master.xml") public class BankConfig { @Value("${jdbc.url}") private String jdbcUrl; @Bean public DataSourse dataSource() { return new SimpleDataSource(jdbcUrl); } } jdbc.url=jdbc:derby://localhost:1527/test jdbc.user=admin jdbc.password=password <context:property-placeholder location="classpath:META-INF/jdbc.properties" /> Properties placeholders
  • 87. 87 | GEEK ACADEMY 2013 Dependency injection @Configuration public class BankServiceConfig { @Autowired private CurrencyRepository currencyRepository; @Bean public CurrencyService currencyService() { return new CurrencyServiceImpl(currencyRepository); } @Bean(name = {"orderBuilder", "builder"}) public OrderBuilder orderBuilder() { return new OrderBuilder(currencyService()); } }
  • 88. 88 | GEEK ACADEMY 2013 Approach to configuration • XML – infrastructure beans • Annotations – working beans • Java – an alternative to the FactoryBean
  • 89. 89 | GEEK ACADEMY 2013 LAB4 Java-based
  • 90. 90 | GEEK ACADEMY 2013 Links • SpringSource • Spring Reference 3.2 • Thank for – Dmitry Noskov
  • 91. 91 | GEEK ACADEMY 2013 Books
  • 93. THANK YOU FOR YOUR TIME GEEK ACADEMY 2013