欢迎来到天天文库
浏览记录
ID:35342122
大小:59.26 KB
页数:6页
时间:2019-03-23
《实验2使用反射api和dom4j实现ioc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、实验2使用反射API和dom4j实现loC实验目的:1.初步掌握反射API的使用。2.初步掌握使用dom4j进行XML解析的方法。3.通过实验理解loC的原理。实验内容:1•使用Eclipse创建一个Gradle项目,转换为dynamicwebmodule*写出gradle中的项目类型,仓库配置和依赖配置。2.项目中Java包及类的结构如下图。v严JavaResourcesp严src/main/javaSBcn.cslgy®app>[JSchoolClass.java>[JjTeacherjavavSB
2、ioc>ConfigParser.java>,J)locExceptionjava>[J)locListenerjavavSBtest>』TestlocServlet.java其中,app包中存放的是POJO类,test包中的Servlet用以获取通过loC创建的Bean列表并输出,ioc包中存放loC的核心代码。在WEB-INF下存放一个ioc.xml定义bean及属性注入,配置文件内容如下。3、/www.springframework•org/schema/beans"xmlns:xsi=tfhttp;//wiv.w3.org/2001/XMLSchema-instance"xmlns:c="http:〃www.springframework.org/schema/c99xmlns:p=nhttp://M)M.springframework.org/schema/p99xsi:schemaLocation=f,/?ttp;//Mviv.springframework.org/schema/be4、anshttp://wvM・springframeuork.org/schema/beans/spring-beans-4.3.xsdw>^^f,>5、ss99id-t9cLassl">6、schooLCLassId"x/alue-9tZB61151ffx/property>Teacher类和Schoolclass类的属性定义如下,需要添加setter、getter和toString方法。publicclassTeacher{pr7、ivateStringname;privateStringid;publicclassSchoolclass{privateStringschoolClassName;privateStringschoolClassId;privateTeachermanager;因为在XML解析和依赖注入中会产生很多种类型的异常,为了简化处理,捕捉这些异常之后再抛出locExceptiono该异常类定义如下。packagecn・cslg・ioc;publicclassIocExceptionextendsExcept8、ion{publicIocException(Throwablecause){super(cause);}}TestlocServlet用以获取通过loC创建的Bean列表并输出,代码如下。^WetServletCVTestlocServlet0)publicclassTestlocServletextendsHttpServlet{privatestaticfinallongseriaLVersionUID■IL;protectedvoi
3、/www.springframework•org/schema/beans"xmlns:xsi=tfhttp;//wiv.w3.org/2001/XMLSchema-instance"xmlns:c="http:〃www.springframework.org/schema/c99xmlns:p=nhttp://M)M.springframework.org/schema/p99xsi:schemaLocation=f,/?ttp;//Mviv.springframework.org/schema/be
4、anshttp://wvM・springframeuork.org/schema/beans/spring-beans-4.3.xsdw>^^f,>5、ss99id-t9cLassl">6、schooLCLassId"x/alue-9tZB61151ffx/property>Teacher类和Schoolclass类的属性定义如下,需要添加setter、getter和toString方法。publicclassTeacher{pr7、ivateStringname;privateStringid;publicclassSchoolclass{privateStringschoolClassName;privateStringschoolClassId;privateTeachermanager;因为在XML解析和依赖注入中会产生很多种类型的异常,为了简化处理,捕捉这些异常之后再抛出locExceptiono该异常类定义如下。packagecn・cslg・ioc;publicclassIocExceptionextendsExcept8、ion{publicIocException(Throwablecause){super(cause);}}TestlocServlet用以获取通过loC创建的Bean列表并输出,代码如下。^WetServletCVTestlocServlet0)publicclassTestlocServletextendsHttpServlet{privatestaticfinallongseriaLVersionUID■IL;protectedvoi
5、ss99id-t9cLassl">6、schooLCLassId"x/alue-9tZB61151ffx/property>Teacher类和Schoolclass类的属性定义如下,需要添加setter、getter和toString方法。publicclassTeacher{pr7、ivateStringname;privateStringid;publicclassSchoolclass{privateStringschoolClassName;privateStringschoolClassId;privateTeachermanager;因为在XML解析和依赖注入中会产生很多种类型的异常,为了简化处理,捕捉这些异常之后再抛出locExceptiono该异常类定义如下。packagecn・cslg・ioc;publicclassIocExceptionextendsExcept8、ion{publicIocException(Throwablecause){super(cause);}}TestlocServlet用以获取通过loC创建的Bean列表并输出,代码如下。^WetServletCVTestlocServlet0)publicclassTestlocServletextendsHttpServlet{privatestaticfinallongseriaLVersionUID■IL;protectedvoi
6、schooLCLassId"x/alue-9tZB61151ffx/property>Teacher类和Schoolclass类的属性定义如下,需要添加setter、getter和toString方法。publicclassTeacher{pr
7、ivateStringname;privateStringid;publicclassSchoolclass{privateStringschoolClassName;privateStringschoolClassId;privateTeachermanager;因为在XML解析和依赖注入中会产生很多种类型的异常,为了简化处理,捕捉这些异常之后再抛出locExceptiono该异常类定义如下。packagecn・cslg・ioc;publicclassIocExceptionextendsExcept
8、ion{publicIocException(Throwablecause){super(cause);}}TestlocServlet用以获取通过loC创建的Bean列表并输出,代码如下。^WetServletCVTestlocServlet0)publicclassTestlocServletextendsHttpServlet{privatestaticfinallongseriaLVersionUID■IL;protectedvoi
此文档下载收益归作者所有