10.3 Developing Spring 1.2 AOP applications
This section will show you an example of horror, FBI agents have been involved in your life, you do everything in their surveillance, including chatting QQ, bubble mm, which in real life is real, for the safety and stability of the people, the suspect to carry out the necessary monitoring is necessary.
Note: Although this chapter introduces a variety of AOP implementations, however, in the actual project, as long as the use of one can achieve the purpose (because spring's AOP exist in a variety of ways, fully mastered or quite complex), other methods for reference only, do not like the same as the study of "anise" word of the N-type, This is out of the original purpose of learning technology: learning is to solve problems, not to show their own. In addition, if the consequences of misuse of AOP in a project are a significant reduction in the execution efficiency of the system, even improper configuration can lead to a dead loop. Remember a truth: the more complex the system, the lower the efficiency, the greater the likelihood of failure. Another piece of advice: do not use AOP on the server log, or printing unnecessary debugging information on the server, which can only be harmful to the system, log output is single-threaded operation, remember. To do a project, in general, the less the function the better. The master more time only can make the destructive power, is not easy to maintain the garbage system.
10.3.1 Development Man Object
This is a very simple project, modeled on the previous section, creating projects and adding spring development functionality, with the addition of the Spring 2.0 AOP libraries in the library. Because the class library of Spring 2.0 is compatible with 1.2, 2.0 is used here. The project name is SPRING1_2AOP. Next we want to create a free person's object, he has chatted QQ and the bubble mm these two methods, but also has a name attribute. OK, first set up this class:
/**
* with chat QQ and bubble mm two behavior of the person object, there is also a user name attribute. * @author Beansoft*/public class Man {private String name; Public
String GetName () {return
name;
}
public void SetName (String name) {
this.name = name;
}
public void QQ () {
System.out.println ("I am chatting qq");
}
public void mm () {
System.out.println ("I am in the bubble mm");
}
}
List 10.6 Man type source code