Java series: My first spring AOP exercise

Source: Internet
Author: User

See "Spring in action" for some time, have been understood, but to understand and do their own writing is really two different things, it took a few hours to start installing Spring, started using Di, and then using AOP, in the process of writing AOP example code encountered a compilation error, Debugging for a long time, finally found willing to, less add a jar package, added in the pom file after the OK.

1  Packagecom. Dbinterface.config;2 3  Public Interfacesetuptable {4      Public intReadsetupnodebynodetypeid (intNodeType,intNodeId,Booleanincludechild); 5      Public intreadallnodes ();6      Public intWriteNode (intNodeType,intnodeId, String nodeName);7      Public intDeletenode (intNodeType,intnodeId);8}

 Packagecom. Dbinterface;ImportCom. dbinterface.config.*; Public classDbinterface { Publicsetuptable getsetuptable () {returnsetuptable; }     Public voidsetsetuptable (setuptable setuptable) { This. setuptable =setuptable; }     Publicrealtimetable getrealtimetable () {returnrealtimetable; }     Public voidsetrealtimetable (realtimetable realtimetable) { This. realtimetable =realtimetable; }     Publiccommandtable getcommandtable () {returncommandtable; }     Public voidsetcommandtable (commandtable commandtable) { This. commandtable =commandtable; }        Privatesetuptable setuptable; Privaterealtimetable realtimetable; Privatecommandtable commandtable;}

 Packagecom. DBINTERFACEFORPG;Importcom. DbInterface.config.SetupTable; Public classSetuptableforpgImplementssetuptable { Public intReadsetupnodebynodetypeid (intNodeType,intNodeId,Booleanincludechild) {System.out.println (String.Format ("Readsetupnodebynodetypeid, nodetype=%d, nodeid=%d, includechild=%b", NodeType, NodeId, Includechild)); return0; }     Public intreadallnodes () {System.out.println ("Readallnodes"); return0; }     Public intWriteNode (intNodeType,intnodeId, String nodeName) {System.out.println (String.Format ("WriteNode, nodetype=%d, nodeid=%d, nodename=%s", NodeType, NodeId, NodeName)); return0; }     Public intDeletenode (intNodeType,intnodeId) {System.out.println (String.Format ("Deletenode, nodetype=%d, nodeid=%d", NodeType, nodeId)); return0; }}

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"Xmlns:c= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/C"Xmlns:context= "Http://www.springframework.org/schema/context"xmlns:p= "http://www.springframework.org/schema/p"Xmlns:util= "Http://www.springframework.org/schema/util"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-4.2.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/ Spring-aop-4.2.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context-4.2.xsd Http://www.springframework.org/schema/util http://www.springframework.org/schema/util/ Spring-util-4.2.xsd ">        <Aop:config>        <Aop:aspectref= "Logger">                    <Aop:pointcutID= "Dbmethod"expression= "Execution (* com. dbinterfaceforpg.setuptableforpg.* (..)) " />                <Aop:beforePointcut-ref= "Dbmethod"Method= "Logbefore" />                        <Aop:afterPointcut-ref= "Dbmethod"Method= "Logafter" />        </Aop:aspect>    </Aop:config>        <BeanID= "Dbinterface"class= "com. Dbinterface.dbinterface "Autowire= "Bytype"/>    <BeanID= "Setuptable"class= "com. DBINTERFACEFORPG.SETUPTABLEFORPG "/>    <BeanID= "Logger"class= "com. PecTrend.util.LoggerWithMethodName "/>    </Beans>

 Public classApp { Public Static voidMain (string[] args) {ApplicationContext ctx=NewClasspathxmlapplicationcontext ("Pectrend.xml"); Dbinterface Dbinterface= (dbinterface) ctx.getbean ("Dbinterface"); if(Dbinterface.getsetuptable ()! =NULL) dbinterface.getsetuptable (). Readsetupnodebynodetypeid (123, 456,false); ElseSystem.out.println ("Assembly Setuptable Failed"); }}

Java series: My first spring AOP exercise

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.