Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dependency Injection JAVA EE - Spring Framework. Inner Beans As you know Java inner classes are defined within the scope of other classes, similarly,

Similar presentations


Presentation on theme: "Dependency Injection JAVA EE - Spring Framework. Inner Beans As you know Java inner classes are defined within the scope of other classes, similarly,"— Presentation transcript:

1 Dependency Injection JAVA EE - Spring Framework

2 Inner Beans As you know Java inner classes are defined within the scope of other classes, similarly, inner beans are beans that are defined within the scope of another bean. Thus, a element inside the or elements is called inner bean.

3 Example: My aim is to create an application where I can add users into database. Step 1: Use hibernate library for database connection and manipulation Step 2: Create bean called DBConnect for database connection Step 3: Use DBConnect bean inside of UserBean

4 DBConnect.java class

5 hibernate.cfg.xml configuration XML file

6 UserBean.java class

7 applicationContext.xml configuration XML file

8 AddUser Servlet class

9 Injecting Collection You have seen how to configure primitive data type using value attribute and object references using ref attribute of the tag in your Bean configuration file. Both the cases deal with passing singular value to a bean.

10 Types of collection configuration elements ElementDescription This helps in wiring ie injecting a list of values, allowing duplicates. This helps in wiring a set of values but without any duplicates. This can be used to inject a collection of name- value pairs where name and value can be of any type. This can be used to inject a collection of name- value pairs where the name and value are both Strings.

11 Example:

12 Bean injection

13 Beans.xml

14 Developing Project with using inheritance In project Development we should use inherit beans from parent beans. We can create an ApplicationBean class, where I have property of DBConnect bean. All my beans will be inherited from ApplicationBean class.

15 ApplicationBean.java bean class

16 UserBean class is inherited from ApplicationBean

17 applicationContext.xml

18 Thank you for attention


Download ppt "Dependency Injection JAVA EE - Spring Framework. Inner Beans As you know Java inner classes are defined within the scope of other classes, similarly,"

Similar presentations


Ads by Google