SlideShare ist ein Scribd-Unternehmen logo
1 von 34
mustafa daşgın mdasgin.blogspot.com mustafa.dasgin@prime.com.tr Spring
Expert One-on-One J2EE Design and Development 	(Rod Johnson) Sıradan Java sınıflarına yetenekler kazandırır. Transactions, Monitoring, Concurrency, Remoting Bağımlılık aktarımını üstlenir Modüler yapılı Core Veri erişimi/entegrasyonu Web AOP Test Spring’e Giriş
Spring Modülleri
Konfigürasyona göre “bean” yaratıp yönetimini üstlenir XML tabanlı Notlandırma (Annotation) tabanlı Java tabanlı org.springframework.context.ApplicationContext  ClassPathXmlApplicationContext FileSystemXmlApplicationContext XmlWebApplicationContext AnnotationConfigApplicationContext AnnotationConfigWebApplicationContext IoC Container
IoC Container (Devam)
XML Tabanlı Konfigürasyon <beans xmlns=“...> <bean id=“userService" class=“com.prime.UserServiceImpl"> <property name=“userDao" ref=“userDao"/> <!– diger ek tanımlamalar --> </bean> <bean id=“userDao" class=“com.prime.UserDaoImpl"> <!– diger ek tanımlamalar --> </bean> </beans
Notlandırma Tabanlı Konfig. <beans xmlns=“...> <context:component-scan base-package="org.example"/> </beans> @Service //@Component @Scope("prototype") publicclassSimpleMovieLister {  @Autowired//@Resource privateMovieFindermovieFinder; publicSimpleMovieLister(MovieFindermovieFinder) { this.movieFinder= movieFinder; } } @Repository //@Component publicclassJpaMovieFinderimplementsMovieFinder {  // implementation elided for clarity }
AnnotationConfigWebApplicationContext CGLIB jar gerekli Java Tabanlı Konfigürasyon @Configuration publicclassAppConfig{ @Bean(name = "myFoo",initMethod= "init") @Scope("prototype") publicFoofoo() {  returnnewFoo(bar()); }  @Bean  publicBar bar() { return newBar();  }  }
IoC Container tarafından yaratılıp, bağımlılıkları ve yaşam döngüsü yönetilen basit Java nesneleri (POJO) Tanımlanırken; Sınıfı id ve/veya ismi Scope değeri Bağımlılıkları Yaşam döngüsü metotları belirtilebilir. Container 3 farklı yöntemle beanleri yaratır: Sınıfın yapıcısı (constructor) static factory metot instance factory metot Bean Nedir?
Yapıcı ile Static Factory metot ile Bean Yaratma Yöntemleri <bean id="exampleBean" class="examples.ExampleBean"/> <bean id="clientService" class="examples.ClientFactoryService“ factory-method="createClient"/> publicclassClientFactoryService {  publicstaticClientServicecreateClient() {  	new ClientService();  } }
Instance Factory metot ile Bean Yaratma Yöntemleri (Devam) <bean id="serviceLocator" class="examples.DefaultServiceLocator“/> <bean id="clientService“ factory-bean="serviceLocator“ factory-method="createClientServiceInstance"/> publicclassDefaultServiceLocator {  publicClientServicecreateClientServiceInstance() { returnnew ClientService(); } }
Bean Scopeları <web-app> ...  <listener> <listener-class> org.springframework.web.context.request.RequestContextListener</listener-class> </listener>  ... </web-app>
Singleton Scope
Prototype Scope
org.springframework.beans.factory.InitializingBean org.springframework.beans.factory.DisposableBean Bean Yaşam Döngüsü <bean id="exampleBean" class="examples.ExampleBean"/> publicclassExampleBeanimplementsInitializingBean, DisposableBean{  publicvoidafterPropertiesSet() { // do some initialization work } publicvoid destroy() {  // do some destruction work } }
init-method destroy-method Bean Yaşam Döngüsü (Devam) <bean id="exampleBean" class="examples.ExampleBean" init-method="init“ destroy-method=“cleanup”/> publicclassExampleBean {  publicvoid init() {  // do some initialization work }  publicvoid cleanup() {  // do some destruction work } }
@PostConstruct @PreDestroy Bean Yaşam Döngüsü (Devam) publicclassExampleBean { @PostConstruct publicvoidinit() {  //... }  @PreDestroy publicvoidcleanup() {  //... } }
Yapıcı ile Aktarım Bağımlılık Aktarımı packagex.y;  publicclassFoo {  publicFoo(Bar bar, Bazbaz) {  // ... } } <beans>  <bean id="foo" class="x.y.Foo"> <constructor-arg ref="bar"/> <constructor-arg ref="baz"/> </bean> <bean id="bar" class="x.y.Bar"/> <bean id="baz" class="x.y.Baz"/> </beans>
Yapıcı ile Aktarım (Devam..) Bağımlılık Aktarımı (Devam) <bean id="exampleBean" class="examples.ExampleBean"> <constructor-arg index="0" value="7500000"/> <constructor-arg index="1" value="42"/> </bean> <bean id="exampleBean" class="examples.ExampleBean"> <constructor-arg name="years" value="7500000"/> <constructor-arg name="ultimateanswer" value="42"/> </bean>
Setter Metotları ile Aktarım Bağımlılık Aktarımı (Devam..) <bean id="exampleBean" class="examples.ExampleBean“> <property name="beanOne"> <ref bean="anotherExampleBean"/> </property> <property name="beanTwo" ref="yetAnotherBean"/> <property name="integerProperty" value="1"/> </bean> <bean id="anotherExampleBean" class="examples.AnotherBean"/> <bean id="yetAnotherBean" class="examples.YetAnotherBean"/>
Primitive Değerlerin Aktarımı packageexamples; publicclassExampleBean {  privateintyears; String ultimateAnswer;  publicExampleBean(int years, String ultimateAnswer) { this.years= years; this.ultimateAnswer= ultimateAnswer; } } <bean id="exampleBean" class="examples.ExampleBean"> <constructor-arg type="int" value="7500000"/>  <constructor-arg type="java.lang.String" value="42"/> </bean>
Collection Yapıların Aktarımı <bean id="moreComplexObject" class="example.ComplexObject"> <!-- java.util.Properties --> <property name="adminEmails"> <props> <prop key="administrator">admin@expl.org</prop> <prop key="support">support@expl.org</prop> <prop key="dev">development@expl.org</prop> </props> </property> 	<!– java.util.List <property name="someList"> <list> <value>a list element</value> <ref bean="myDataSource" /> </list> </property>
Collection Yapılarının Akt. (Devam) <!-- java.util.Map <property name="someMap"> <map> <entry key="entry" value="just some string"/> <entry key ="a ref" value-ref="myDataSource"/> </map> </property> <!-- java.util.Set --> <property name="someSet"> <set> <value>just some string</value> <ref bean="myDataSource" /> </set> </property> </bean>
Null ve Boş String Aktarımı <!-- Boş String --> <bean class="ExampleBean"> <property name="email" value=""/> </bean> <!-- Null --> <bean class="ExampleBean"> <property name="email"><null/></property> </bean>
Modları: byName byType constructor Primitive tipler için kullanılamaz Aynı tip değerinde birden fazla aday bean varsa hata oluşur. Autowire <bean id=“userService” class=“services.UserService” autowire=“byName”/>
web.xml JSF ile Entegrasyon <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> ... <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param>
faces-config.xml ApplicationContext erişimi: JSF ile Entegrasyon (Devam) <faces-config> <application> <el-resolver> org.springframework.web.jsf.el.SpringBeanFacesELResolver </el-resolver> ...  </application> </faces-config> ApplicationContextctx = FacesContextUtils.getWebApplicationContext( FacesContext.getCurrentInstance());
Farklı transaction APIleri (JTA, JDBC, Hibernate, JPA) üzerine ortak bir model sunar. Transaction gerçekleştirimi değişse bile kodta değişiklik yapmaya gerek yok. Programlama veya tanımlama ile transaction tanımları yapılabilir. Basit API Spring Transaction Desteği
JDBC – DataSourceTransactionManager JTA – JtaTransactionManager Hibernate – HibernateTransactionManager JPA - JpaTransactionManager PlatformTransactionManager <bean id=“txManager"            class="org.springframework.orm.jpa.JpaTransactionManager“ <property name=“entityManagerFactory” ref="entityManagerFactory"/> </bean> <bean id=“entityManagerFactory“ class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 	<property name=“dataSource” ref=“dataSource”/> 	... </bean>
XML  ile Transaction Tanımlama <aop:config> <aop:pointcut id="serviceOperation“ expression="execution(* x.y.service..*Service.*(..))"/>  <aop:advisorpointcut-ref="serviceOperation“ advice-ref="txAdvice"/> </aop:config> <bean id="fooService" class="x.y.service.DefaultFooService"/> <bean id="anotherService" class="org.xyz.SomeService"/> <tx:advice id="txAdvice“transaction-manager="txManager" > <tx:attributes> <tx:method name="get*" read-only="true"/> <tx:method name="*"/> </tx:attributes>
Notlandırma ile Transaction Tanım. @Transactional(readOnly = true) publicclassDefaultFooServiceimplementsFooService{ publicFoogetFoo(String fooName) { // do something }  @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW) publicvoidupdateFoo(Foofoo) { // do something } } <bean id="fooService" class="x.y.service.DefaultFooService"/>  <tx:annotation-driven transaction-manager="txManager"/>
LocalEntityManagerFactoryBean EntityManagerFactory’i JNDI’dan elde etme LocalContainerEntityManagerFactoryBean JPA Desteği
JPA Desteği (Devam) <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="persistenceUnitName" value="simpleJpa"/> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="true"/> <property name="generateDdl" value="true"/> <property name="database" value="HSQL"/> </bean> </property> </bean>
Spring Reference Documantation http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/ Kaynak

Weitere ähnliche Inhalte

Ähnlich wie Spring

Uma introdução ao framework Spring
Uma introdução ao framework SpringUma introdução ao framework Spring
Uma introdução ao framework Springelliando dias
 
JSUG - Spring by Christoph Pickl
JSUG - Spring by Christoph PicklJSUG - Spring by Christoph Pickl
JSUG - Spring by Christoph PicklChristoph Pickl
 
자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)
자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)
자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)DK Lee
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesJohn Brunswick
 
Apache Camel - WJax 2008
Apache Camel - WJax 2008Apache Camel - WJax 2008
Apache Camel - WJax 2008inovex GmbH
 
Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvcGuo Albert
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixBruce Snyder
 
Object Oreinted Approach in Coldfusion
Object Oreinted Approach in ColdfusionObject Oreinted Approach in Coldfusion
Object Oreinted Approach in Coldfusionguestcc9fa5
 
Developing and testing ajax components
Developing and testing ajax componentsDeveloping and testing ajax components
Developing and testing ajax componentsIgnacio Coloma
 
Introduction to JSF
Introduction toJSFIntroduction toJSF
Introduction to JSFSoftServe
 
Spring talk111204
Spring talk111204Spring talk111204
Spring talk111204ealio
 
Seam Introduction
Seam IntroductionSeam Introduction
Seam Introductionihamo
 

Ähnlich wie Spring (20)

Uma introdução ao framework Spring
Uma introdução ao framework SpringUma introdução ao framework Spring
Uma introdução ao framework Spring
 
JBoss Seam 1 part
JBoss Seam 1 partJBoss Seam 1 part
JBoss Seam 1 part
 
Spring overview
Spring overviewSpring overview
Spring overview
 
Jsfsunum
JsfsunumJsfsunum
Jsfsunum
 
Spring and DWR
Spring and DWRSpring and DWR
Spring and DWR
 
Jsp
JspJsp
Jsp
 
JSUG - Spring by Christoph Pickl
JSUG - Spring by Christoph PicklJSUG - Spring by Christoph Pickl
JSUG - Spring by Christoph Pickl
 
자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)
자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)
자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)
 
I Feel Pretty
I Feel PrettyI Feel Pretty
I Feel Pretty
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server Pages
 
Apache Camel - WJax 2008
Apache Camel - WJax 2008Apache Camel - WJax 2008
Apache Camel - WJax 2008
 
Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvc
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMix
 
Object Oreinted Approach in Coldfusion
Object Oreinted Approach in ColdfusionObject Oreinted Approach in Coldfusion
Object Oreinted Approach in Coldfusion
 
Developing and testing ajax components
Developing and testing ajax componentsDeveloping and testing ajax components
Developing and testing ajax components
 
Introduction to JSF
Introduction toJSFIntroduction toJSF
Introduction to JSF
 
Os Johnson
Os JohnsonOs Johnson
Os Johnson
 
Spring talk111204
Spring talk111204Spring talk111204
Spring talk111204
 
Seam Introduction
Seam IntroductionSeam Introduction
Seam Introduction
 
C:\fakepath\jsp01
C:\fakepath\jsp01C:\fakepath\jsp01
C:\fakepath\jsp01
 

Spring

  • 1. mustafa daşgın mdasgin.blogspot.com mustafa.dasgin@prime.com.tr Spring
  • 2. Expert One-on-One J2EE Design and Development (Rod Johnson) Sıradan Java sınıflarına yetenekler kazandırır. Transactions, Monitoring, Concurrency, Remoting Bağımlılık aktarımını üstlenir Modüler yapılı Core Veri erişimi/entegrasyonu Web AOP Test Spring’e Giriş
  • 4. Konfigürasyona göre “bean” yaratıp yönetimini üstlenir XML tabanlı Notlandırma (Annotation) tabanlı Java tabanlı org.springframework.context.ApplicationContext  ClassPathXmlApplicationContext FileSystemXmlApplicationContext XmlWebApplicationContext AnnotationConfigApplicationContext AnnotationConfigWebApplicationContext IoC Container
  • 6. XML Tabanlı Konfigürasyon <beans xmlns=“...> <bean id=“userService" class=“com.prime.UserServiceImpl"> <property name=“userDao" ref=“userDao"/> <!– diger ek tanımlamalar --> </bean> <bean id=“userDao" class=“com.prime.UserDaoImpl"> <!– diger ek tanımlamalar --> </bean> </beans
  • 7. Notlandırma Tabanlı Konfig. <beans xmlns=“...> <context:component-scan base-package="org.example"/> </beans> @Service //@Component @Scope("prototype") publicclassSimpleMovieLister { @Autowired//@Resource privateMovieFindermovieFinder; publicSimpleMovieLister(MovieFindermovieFinder) { this.movieFinder= movieFinder; } } @Repository //@Component publicclassJpaMovieFinderimplementsMovieFinder { // implementation elided for clarity }
  • 8. AnnotationConfigWebApplicationContext CGLIB jar gerekli Java Tabanlı Konfigürasyon @Configuration publicclassAppConfig{ @Bean(name = "myFoo",initMethod= "init") @Scope("prototype") publicFoofoo() { returnnewFoo(bar()); } @Bean publicBar bar() { return newBar(); } }
  • 9. IoC Container tarafından yaratılıp, bağımlılıkları ve yaşam döngüsü yönetilen basit Java nesneleri (POJO) Tanımlanırken; Sınıfı id ve/veya ismi Scope değeri Bağımlılıkları Yaşam döngüsü metotları belirtilebilir. Container 3 farklı yöntemle beanleri yaratır: Sınıfın yapıcısı (constructor) static factory metot instance factory metot Bean Nedir?
  • 10. Yapıcı ile Static Factory metot ile Bean Yaratma Yöntemleri <bean id="exampleBean" class="examples.ExampleBean"/> <bean id="clientService" class="examples.ClientFactoryService“ factory-method="createClient"/> publicclassClientFactoryService { publicstaticClientServicecreateClient() { new ClientService(); } }
  • 11. Instance Factory metot ile Bean Yaratma Yöntemleri (Devam) <bean id="serviceLocator" class="examples.DefaultServiceLocator“/> <bean id="clientService“ factory-bean="serviceLocator“ factory-method="createClientServiceInstance"/> publicclassDefaultServiceLocator { publicClientServicecreateClientServiceInstance() { returnnew ClientService(); } }
  • 12. Bean Scopeları <web-app> ... <listener> <listener-class> org.springframework.web.context.request.RequestContextListener</listener-class> </listener> ... </web-app>
  • 15. org.springframework.beans.factory.InitializingBean org.springframework.beans.factory.DisposableBean Bean Yaşam Döngüsü <bean id="exampleBean" class="examples.ExampleBean"/> publicclassExampleBeanimplementsInitializingBean, DisposableBean{ publicvoidafterPropertiesSet() { // do some initialization work } publicvoid destroy() { // do some destruction work } }
  • 16. init-method destroy-method Bean Yaşam Döngüsü (Devam) <bean id="exampleBean" class="examples.ExampleBean" init-method="init“ destroy-method=“cleanup”/> publicclassExampleBean { publicvoid init() { // do some initialization work } publicvoid cleanup() { // do some destruction work } }
  • 17. @PostConstruct @PreDestroy Bean Yaşam Döngüsü (Devam) publicclassExampleBean { @PostConstruct publicvoidinit() { //... } @PreDestroy publicvoidcleanup() { //... } }
  • 18. Yapıcı ile Aktarım Bağımlılık Aktarımı packagex.y; publicclassFoo { publicFoo(Bar bar, Bazbaz) { // ... } } <beans> <bean id="foo" class="x.y.Foo"> <constructor-arg ref="bar"/> <constructor-arg ref="baz"/> </bean> <bean id="bar" class="x.y.Bar"/> <bean id="baz" class="x.y.Baz"/> </beans>
  • 19. Yapıcı ile Aktarım (Devam..) Bağımlılık Aktarımı (Devam) <bean id="exampleBean" class="examples.ExampleBean"> <constructor-arg index="0" value="7500000"/> <constructor-arg index="1" value="42"/> </bean> <bean id="exampleBean" class="examples.ExampleBean"> <constructor-arg name="years" value="7500000"/> <constructor-arg name="ultimateanswer" value="42"/> </bean>
  • 20. Setter Metotları ile Aktarım Bağımlılık Aktarımı (Devam..) <bean id="exampleBean" class="examples.ExampleBean“> <property name="beanOne"> <ref bean="anotherExampleBean"/> </property> <property name="beanTwo" ref="yetAnotherBean"/> <property name="integerProperty" value="1"/> </bean> <bean id="anotherExampleBean" class="examples.AnotherBean"/> <bean id="yetAnotherBean" class="examples.YetAnotherBean"/>
  • 21. Primitive Değerlerin Aktarımı packageexamples; publicclassExampleBean { privateintyears; String ultimateAnswer; publicExampleBean(int years, String ultimateAnswer) { this.years= years; this.ultimateAnswer= ultimateAnswer; } } <bean id="exampleBean" class="examples.ExampleBean"> <constructor-arg type="int" value="7500000"/> <constructor-arg type="java.lang.String" value="42"/> </bean>
  • 22. Collection Yapıların Aktarımı <bean id="moreComplexObject" class="example.ComplexObject"> <!-- java.util.Properties --> <property name="adminEmails"> <props> <prop key="administrator">admin@expl.org</prop> <prop key="support">support@expl.org</prop> <prop key="dev">development@expl.org</prop> </props> </property> <!– java.util.List <property name="someList"> <list> <value>a list element</value> <ref bean="myDataSource" /> </list> </property>
  • 23. Collection Yapılarının Akt. (Devam) <!-- java.util.Map <property name="someMap"> <map> <entry key="entry" value="just some string"/> <entry key ="a ref" value-ref="myDataSource"/> </map> </property> <!-- java.util.Set --> <property name="someSet"> <set> <value>just some string</value> <ref bean="myDataSource" /> </set> </property> </bean>
  • 24. Null ve Boş String Aktarımı <!-- Boş String --> <bean class="ExampleBean"> <property name="email" value=""/> </bean> <!-- Null --> <bean class="ExampleBean"> <property name="email"><null/></property> </bean>
  • 25. Modları: byName byType constructor Primitive tipler için kullanılamaz Aynı tip değerinde birden fazla aday bean varsa hata oluşur. Autowire <bean id=“userService” class=“services.UserService” autowire=“byName”/>
  • 26. web.xml JSF ile Entegrasyon <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> ... <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param>
  • 27. faces-config.xml ApplicationContext erişimi: JSF ile Entegrasyon (Devam) <faces-config> <application> <el-resolver> org.springframework.web.jsf.el.SpringBeanFacesELResolver </el-resolver> ... </application> </faces-config> ApplicationContextctx = FacesContextUtils.getWebApplicationContext( FacesContext.getCurrentInstance());
  • 28. Farklı transaction APIleri (JTA, JDBC, Hibernate, JPA) üzerine ortak bir model sunar. Transaction gerçekleştirimi değişse bile kodta değişiklik yapmaya gerek yok. Programlama veya tanımlama ile transaction tanımları yapılabilir. Basit API Spring Transaction Desteği
  • 29. JDBC – DataSourceTransactionManager JTA – JtaTransactionManager Hibernate – HibernateTransactionManager JPA - JpaTransactionManager PlatformTransactionManager <bean id=“txManager" class="org.springframework.orm.jpa.JpaTransactionManager“ <property name=“entityManagerFactory” ref="entityManagerFactory"/> </bean> <bean id=“entityManagerFactory“ class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name=“dataSource” ref=“dataSource”/> ... </bean>
  • 30. XML ile Transaction Tanımlama <aop:config> <aop:pointcut id="serviceOperation“ expression="execution(* x.y.service..*Service.*(..))"/> <aop:advisorpointcut-ref="serviceOperation“ advice-ref="txAdvice"/> </aop:config> <bean id="fooService" class="x.y.service.DefaultFooService"/> <bean id="anotherService" class="org.xyz.SomeService"/> <tx:advice id="txAdvice“transaction-manager="txManager" > <tx:attributes> <tx:method name="get*" read-only="true"/> <tx:method name="*"/> </tx:attributes>
  • 31. Notlandırma ile Transaction Tanım. @Transactional(readOnly = true) publicclassDefaultFooServiceimplementsFooService{ publicFoogetFoo(String fooName) { // do something } @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW) publicvoidupdateFoo(Foofoo) { // do something } } <bean id="fooService" class="x.y.service.DefaultFooService"/> <tx:annotation-driven transaction-manager="txManager"/>
  • 32. LocalEntityManagerFactoryBean EntityManagerFactory’i JNDI’dan elde etme LocalContainerEntityManagerFactoryBean JPA Desteği
  • 33. JPA Desteği (Devam) <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="persistenceUnitName" value="simpleJpa"/> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="true"/> <property name="generateDdl" value="true"/> <property name="database" value="HSQL"/> </bean> </property> </bean>
  • 34. Spring Reference Documantation http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/ Kaynak

Hinweis der Redaktion

  1. All @Configuration classes are subclassed at startup-time with CGLIB. In the subclass, the child method checks the container first for any cached (scoped) beans before it calls the parent method and creates a new instance.There are a few restrictions due to the fact that CGLIB dynamically adds features at startup-time:Configuration classes should not be finalThey should have a constructor with no arguments
  2. Code is cleaner with the DI principle and decoupling is more effective when objects are provided with their dependencies
  3. Keep in mind that to make “Constructor argument name” work out of the box your code must be compiled with the debug flag enabled so that Spring can look up the parameter name from the constructor. If you can&apos;t compile your code with debug flag (or don&apos;t want to) you can use @ConstructorProperties JDK annotation to explicitly name your constructor arguments.
  4. In proxy mode (which is the default), only external method calls coming in through the proxy are intercepted. This means that self-invocation, in effect, a method within the target object calling another method of the target object, will not lead to an actual transaction at runtime even if the invoked method is marked with @Transactional.