spring session

Post on 25-Jan-2015

58 Views

Category:

Education

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Spring Session in Orange Labs Cairo.

TRANSCRIPT

Spring Framework 3.0And beyond

Gamal Shaaban

What’s Spring?

“Most Popular Application Development Framework for Enterprise Java.”

History Of Spring

• Expert One-on-One J2EE Design and Development (Oct-02) by Rob Johnson.

• Spring 2.0 released in Oct-06• Spring 2.5 released in Nov-07• Spring 3.0 released in Dec-09• Current version of Spring 3.2 released in Mar-

13

IoC(Inversion of control) & Container

• Spring Framework is the foundation of all the Spring extensions.

• Central of the Spring Framework is its inversion of control container & POJO Container.

• The container is responsible for managing beans lifecycles.

Bean ScopesSingleton Scopes a single bean definition to a single object instance per Spring IoC container.

Prototype Scopes a single bean definition to any number of object instances.

Request Scopes a single bean definition to the lifecycle of a single HTTP request; that is each and every HTTP request will have its own instance of a bean created off the back of a single bean definition. Only valid in the context of a web-aware Spring ApplicationContext.

Session Scopes a single bean definition to the lifecycle of a HTTP Session. Only valid in the context of a web-aware Spring ApplicationContext.

Global session Scopes a single bean definition to the lifecycle of a global HTTP Session. Typically only valid when used in a portlet context. Only valid in the context of a web-aware Spring ApplicationContext.

Dependency Injection• Any nontrivial application (pretty much anything more complex than a

Hello World example) is made up of two or more classes that collaborate with each other to perform some business logic. Traditionally, each object is responsible for obtaining its own references to the objects it collaborates with (its dependencies). This can lead to highly coupled and hard-to-test code.

• The phrase dependency injection may sound intimidating, conjuring up notions of a complex programming technique or design pattern. But as it turns out, DI isn’t nearly as complex as it sounds. By applying DI in your projects, you’ll find that your code will become significantly simpler, easier to understand, and easier to test.

Bean Wiring<bean id="sequenceGenerator“ class="com.orange.plc.pojo.Sequence">

<property name="initial" value="100000" /><property name="suffixes">< l i s t >

<value>A</value><bean class="j a v a . n e t . U R L ">

<constructor-arg value="http" /><constructor-arg value="www.apress.com" /><constructor-arg value="/" />

</bean>< / l i s t ></property>

</bean>

AOP (Aspect Oriented Programming)

• What’s an Aspect?• What’s Cross-cutting concerns?• What’s Aspect Oriented Programming.• Spring AOP & AspectJ (proxy pattern-based).

AOP• Calls to systemwide concerns such as logging and security are often

scattered about in modules where those concerns are not their primary concern.

AOP• Using AOP, systemwide concerns blanket the components that they

impact. This leaves the application components to focus on their specific business functionality.

AOP WEAVING

• Weaving is the process of applying aspects to a target object to create a new proxied object. The aspects are woven into the target object at the specified join points. The weaving can take place at several points in the target object’s lifetime:– Compile time: Aspects are woven in when the target class is compiled. This requires a

special compiler. AspectJ weaving compiler weaves aspects this way.– Classload time: Aspects are woven in when the target class is loaded into the JVM. This

requires a special ClassLoader that enhances that target class bytecode before the class is introduced into the application. AspectJ load-time weaving (LTW) support weaves aspects in this way.

– Runtime: Aspects are woven in sometime during the execution of the application. Typically, an AOP container will dynamically generate a proxy object that will delegate to the target object while weaving in the aspects. This is how Spring AOP aspects are woven.

Target Opject & Proxy• Spring aspects are implemented as proxies that wrap the target object.

The proxy handles method calls, performs additional aspect logic, and then invokes the target method.

Questions ?

Thank You

top related