1 Preparatory work
(Download on Demand)
- Eclipse Download: http://www.eclipse.org/downloads/eclipse-packages/;
- Spring Download: http://repo.spring.io/libs-release-local/org/springframework/spring/version of the optional;
- Spring AOP 3 Additional packages required: http://download.csdn.net/download/lk_lxn/6397895
2 Spring IDE
Help->eclipse marketplace->find "Spring"->install
Select the desired project installation and restart Eclipse.
Remember to restart after installation
3 Importing the required packages
There are many ways to do this, and I'll stick to my method.
Project Right->build path->configure build path->libraries->add library->user library->user Librarys
->new-> Input Library Name->add External jars-> Select the desired package
---Check the lib->finish->ok; at the Add library
My approach seems to be more troublesome ...
4 Starter Projects
Full Catalog
Performer.java
1 Packagecom.spring;2 3 ImportJava.text.SimpleDateFormat;4 Importjava.util.Date;5 6 Public classPerformer {7 Privateinstrument ins;8 PublicPerformer (instrument ins) {9 This. ins=ins;//tightly coupled with violinTen } One Public voidPlay () { A Ins.play (); - } - } the classrecord{ - PrivateSimpleDateFormat DF =NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); - Public voidStartTime () { -System.out.println (Df.format (NewDate ())); + } - Public voidEndtime () { +System.out.println (Df.format (NewDate ())); A } at } - classViolinextendsInstrument { - - Public voidPlay () { -System.out.println ("Violin music!"); - } in } - classInstrument { to voidplay () {}; +}
Performermain.java
Packagecom.spring;ImportOrg.springframework.context.ApplicationContext;ImportOrg.springframework.context.support.ClassPathXmlApplicationContext; Public classPerformermain { Public Static voidMain (string[] args) {//TODO auto-generated Method StubApplicationContext APC =NewClasspathxmlapplicationcontext ("Spring.xml"); Performer Hello= (performer) Apc.getbean ("performer"); Hello.play (); }}
Spring.xml
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/schema/bean S/spring-beans-3.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http: Www.springframework.org/schema/aop/spring-aop.xsd "> <BeanID= "Performer"class= "Com.spring.Performer"> <Constructor-argref= "Violin" /> </Bean> <BeanID= "Violin"class= "Com.spring.Violin"></Bean> <BeanID= "Record"class= "Com.spring.Record"></Bean> <Aop:config> <Aop:aspectref= "Record"> <Aop:pointcutexpression= "Execution (* com.spring.Performer.play (..))"ID= "Play"/> <Aop:beforeMethod= "StartTime"Pointcut-ref= "Play"/> <Aop:afterMethod= "Endtime"Pointcut-ref= "Play"/> </Aop:aspect> </Aop:config></Beans>
Operation Result:
Precautions:
Using AOP tags in the XML file to introduce header file configuration
Error:
Three packets that need to be aspectj are given at the beginning.
Spring Learning Essay (2): Eclipse under Spring environment configuration + Getting Started project