第2课 原书第一章结束 06-04-11

来源:互联网 发布:淘宝卖家信誉页面 编辑:程序博客网 时间:2024/05/05 18:20

1.

What makes Spring-enabled applications different, however, is how these classes are
configured and introduced to each other. Typically, a Spring application has an
XML file

2.

called. You may have noticed that the
greeting can be set in two different ways: by the constructor or by the property’s
setter method.

3.

As it turns out, we’re going to let
the Spring container set the greeting property.

4.

At the root of this simple XML file is the <beans> element, which is the root element
of any Spring configuration file.

5.

the id attribute is used to name the bean greetingService and the class attribute specifies
the bean’s fully qualified class name.

6.

By using <property>, we’re telling the Spring
container to call setGreeting() when setting the property.

7.

The BeanFactory class used here is the Spring container.

8.

logic. Traditionally, each object is responsible for obtaining
its own references to the objects it collaborates with (its dependencies). As
you’ll see, this can lead to highly coupled and hard-to-test code.
Applying IoC, objects are given their dependencies at creation time by some
external entity that coordinates each object in the system. That is, dependencies
are injected into objects. So, IoC means an inversion of responsibility with regard
to how an object obtains references to collaborating objects.

9.

Unit testing is an important part of development.

10.

beast. On one hand, tightly coupled code is difficult
to test, difficult to reuse, difficult to understand, and typically exhibits “whack-amole”
bugs (i.e., fixing one bug results in the creation of one or more new bugs).
On the other hand, completely uncoupled code doesn’t do anything.

11.

A common technique used to reduce coupling is to hide implementation
details behind interfaces

12.

the responsibility of
coordinating collaboration between dependent objects is transferred away from
the objects themselves. And that’s where lightweight container frameworks, such
as Spring, come into play.

13.

 In Spring, there are many ways to wire components together, but the most
common approach is via XML.

14.

In a Spring application, a BeanFactory loads the bean definitions and wires the
beans together.

15.

Notice that
this class knows nothing about the quest the knight will take. Again, the only thing
that knows which type of quest will be given to the knight is the knight.xml file.

16.

No lookup code! The reference to OrderService is given to our class by the Spring
container through the setOrderService() method.

17.

aspect-oriented programming enables you to capture functionality that is
used throughout your application in reusable components.

18.

Aspect-oriented programming is often defined as a programming technique that
promotes separation of concerns within a software system.

19.

A method to add an entry to an address book should only be
concerned with how to add the address and not with whether it is secure or
transactional.

20.

As it is, each knight
must stop and tell the minstrel to compose a
song before the knight can continue with his
quest (as in figure 1.6). Ideally a minstrel would
automatically compose songs without being
explicitly told to do so. A knight shouldn’t know
(or really even care) that their deeds are being
written into song.

21.

the
simplest way to create an aspect-oriented minstrel is to change the minstrel class to
be an implementation of MethodBeforeAdvice

22.

As a subclass of MethodBefore-
Advice, the MinstrelAdvice
class will intercept calls to the
target object’s methods, giving
the before() method an
opportunity to do something
before the target method gets
called.

23.

Applying advice to an object is known as weaving. In Spring, aspects
are woven into objects in the Spring XML file, much in the same way that beans
are wired together.

24.

With EJB it is possible to write components
that are ignorant of the fact that they are in a transactional context or
being secured and then declare the transactional and security policies for those
components in the EJB deployment descriptor.

25.

Although the Spring framework comes packed with several frameworks
and support for several enterprise-level services, it does not come with
much to assist you with security.

26.