Spring笔试考试题目

更新时间:2023-09-29 20:18:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Spring笔试考试题目

考生姓名:________ 考生班级:_______ 评分:_______________________ 一:填空(总分20分)

1.1: Spring 的框架是一个____轻量级________容器,以___IOC_____模式作为核心,从而可以实现应用程序组件的_______松散耦合 ______结构,让应用程序组件可以容易进行测试。 1.2: Spring中实现IoC模式的方法都有_____注入依赖_____________, _____java注解____________, ___________schema XML方式 ________, ________serviceLocator_____________。 1.3: Spring中基于Web的ApplicationContext下可以用到的特有的Bean的作用域都有_request _________________, ______session ___________, _________globalsession _________。

1.4: Spring中的AOP术语的全称是_______面向切面编程_______________(中文)、___aspect-OrientedProgramming_________________(英文),在Spring中它的实现机制是采用__________________动态代理____实现的。 1.5:在Spring AOP中,Advice(增强)被应用至对象之上的过程称之为___缝合_____________(中英文都填),其选择时机有几个时间点,分别是:______编译_______时期、_类别加载_____________时期、和_执行_________________时期。

1.6:配置Spring中的@AspectJ时,需要配置________________标签,以便AOP框架自动使用增强; 该标签有一个proxy-target-class属性,默认为____false__________,表示使用_jdk动态代理治入增强_________代理方式,当配置为时,表示使用___cglib动态代理技术治入增强___________代理方式。

1.7:在Spring AOP中,我们可以通过_______@pointcut_________注解对切点表达式进行命名。

1.8:Spring AOP中,在“进入”连接点的情况下,___最高________优先级的增强会先执行;在“退出”连接点的情况下,_____最高________优先级的增强会最后执行;对于定义在相同切面的增强,根据____声明的顺序_____________来确定执行顺序。

1.9:使用Schema XML配置Spring AOP时,, 和,三者在配置有先后顺序要求,要求的顺序分别是:___________________, _________________,___________________。

1.10:Spring事物管理中,重要的三个概念分别是__transactiondefinition________________ ,_____transactionStatus ____________,____platformtransactiomanger _____________________。 二:选择(注意:单选或者多选混选)(总分20分)

2.1:可以实现IoC (Inversion of Control) 模式的方法都有哪些?_______ABCD_____________

A:依赖注入(Dependency Injection) B:Service Locator C:Java 注解

D:Schema XML方式

2.2:Spring中Bean的自动装配都有哪些选择? _____ABCD_______________ A:By Type B:By Name C:No

D:Constructor方式 E:Autodetect方式

2.3:Spring中ApplicationContext能够用到的Bean的作用域都有哪些? _____ABC_____________ A:Singleton B:Prototype

C:Session D:Response

2.4:我们学习过的Abstract Factory,Prototype,Singleton模式按照设计模式的分类都属于哪种? ___AD_________________ A:创建型设计模式 B:结构型设计模式 C:行为型设计模式

D:对象范围的设计模式

2.5:Bean的基本配置中,如果有诸如List,Set,Map和Properties的属性,那么可以通过下述哪些对应的标签来配置? ______ABCD______________ A: B: C: D:

2.6:Spring的AOP的动态代理机制都有哪些? _______AB_____________ A:CGLib库 B:JDK动态代理 C:Proxy代理 D:Auto代理

2.7:Spring中的@AspectJ切点表达式函数都有哪些? _______ABCD_____________ A:方法切点函数 B:方法入参切点函数 C:目标类切点函数 D:代理类切点函数

2.8:说明下面切面类的增强实施到业务方法int foo(String name)时,其增强各自执行后结果是什么? @Aspect

public class AspectWithMultipleAdviceDeclarations { @Pointcut(\ public void fooExecution() {} @Before(\ public void doBeforeOne() { // ... }

@Before(\ public void doBeforeTwo() { // ... }

@AfterReturning(\ public void doAfterOne() { // ... }

@AfterReturning(\ public void doAfterTwo() { // ... }

} ______ebadc______________(注意顺序)

A:foo

B:doBeforeTwo C:doAfterTwo D:doAfterOne E:doBeforeOne

2.9:下面哪些不支持切点中的通配符,如+, .., 和*? _______abcd_____________ A:@args() B:@within() C:@target() D:@annotation()

2.10:下面哪个是Spring AOP中的引介增强? _______E_____________

A:@Before

B:@AfterReturning C:@Around

D:@AfterThrowing E:@DeclareParents 三:判断对错(总分30分)

3.1:Spring中,我们可以选择DBCP,C3P0来配置数据源。 ( T )

3.2:在Bean的基本配置中,如果某个Bean属性要默认为空,我们可以利用将该属性设置为null来实现;如

3.3:在配置Bean时,内部Bean中的singleton标记及id或name属性将不会被忽略,内部bean总是匿名的且它们总是prototype模式的。同时将内部bean注入到包含该内部bean之外的bean也是可能的。(F ) 3.4:下面配置的Bean,Spring会在启动时,IoC容器默认会将该bean提前进行实例化。

(F ) 3.5:Spring中配置的Bean,要么只能都用Autowire自动装配,要么都不用Autowire自动装配。( F )

3.6:在Spring中,大多数配置的Bean都是Prototype类型的,并且Spring会对Prototype类型的Bean负责其整个生命周期的。 ( F ) 3.7:切点表达式中的通配符“+”:其含义表示按类型匹配指定类的所有类,仅能跟在类名后面。( T ) 3.8:Spring的AOP中,用注解表示的后置增强是@After。 ( F )

3.9:Spring的AOP中,定义在不同的切面里的两个增强都需要在一个相同的连接点中运行,那么除非我们显式指定,否则执行的顺序是未知的。 ( T ) 3.10:Spring AOP中,Advisor是切点和增强的复合体,它可以包含多个切点和增强。( F )

3.11:Spring的AOP中,切点绑定增强方法时,是按名字匹配的,但是在绑定连接点时,是按参数顺序匹配的。 ( T )

3.12:使用Spring统一的DAO异常体系时,如果访问数据资源时失败,如无法获取数据连接,无法获取Hibernate的

会话等,我们可以捕获ConcurrencyFailureException类型的异常。 ( F ) 3.13:Spring中,如果我们的持久层采用Spring提供的模板类来实现,为了要使持久层的方法是多线程安全的,我们可以选择继承Spring提供的支持类xxxSupport。 ( F )

3.14:Spring AOP中,不仅支持方法上的连接点,还支持属性上的连接点。 ( F )

3.15:Spring中,持久层、业务层的Bean一般是加载到Spring容器中的根容器,而为融合Struts框架设计的Action

Bean一般是加载到子容器中的;父容器是可以访问子容器中的Bean元素的。 ( F ) 四:问答题(总分20分)

4.1:请阐述Spring框架和EJB相比较,各自的优缺点?

Spring核心是依赖注入模式 spring可以随时测试 EJB测试非常麻烦

EJB3,0是一个标准的框架

4.2:在Spring IoC核心模式中,试比较三种推荐的依赖注入方式的相同点和不同点?

4.3:请解释你所理解的AOP中的如下概念:增强、切入点、连接点、切面,并说明它们之间的关系。以及Spring的AOP框架是如何用这些概念搭建并实现的,请阐述你的理解?

4.4:说明你Spring中Bean的各种生命周期的理解?

4.5:这里为下面的业务类方法编写了两个切面类,每个切面类中分别定义了一些增强方法,请完成下面的问题。

//业务类定义

package com.cstp;

public class NaiveWaiter implements Waiter{ public void greetTo(String clientName){

System.out.println(\ }

public void serveTo(String clientName, int times){

System.out.println(\”?”+times+\ } }

//第一个切面类的定义

package com.cstp.aspectj.aspectj;

import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; @Aspect

public class PreGreetingAspect{

@Before(\

public void beforeGreeting(){

System.out.println(\ } }

//第二个切面类的定义

package com.cstp.aspectj.advanced;

import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; @Aspect

public class BeforeAspect{

@Before(\ public void bindJoinPointParams(int num,String name){ System.out.println(\ System.out.println(\ System.out.println(\

System.out.println(\ } }

//下面是定义的Spring配置文件beans.xml

xsi:schemaLocation=\ http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-2.0.xsd\ ______________________________(1)

//下面是测试的代码

package com.cstp.aspectj.example;

import org.springframework.aop.aspectj.annotation.AspectJProxyFactory; import org.cstp.NaiveWaiter; import org.cstp.Waiter; public class Test{

public static void main(String[] args){

ApplicationContext tx=new ClassPathXmlApplicationContext(“com/cstp/schema/beans.xml”); NaiveWaiter proxy=tx.getBean(“waiter”); proxy.greetTo(\ proxy.serveTo(\ } }

请回答下面问题:

1).首先,请填写上面的空白(1)处。 2).请写出测试代码运行后的结果。

3).如果我们要把第一个切面类采用Schema XML方式来完成,请写出该种方式的配置文件,只需要写出中配置增强和切点的方式。

五:编程(总分10分)

5.1:下面是一个需要进行事务管理的业务类, package com.cstp.service;

import com.cstp.dao.LoginLogDao; import com.cstp.dao.UserDao; import com.cstp.domain.User;

public class UserServiceImpl implements UserService{ private UserDao userDao; //注入接口对象

private LoginLogDao loginLogDao; //注入接口对象 public void setUserDao(UserDao userDao){ this.userDao=userDao; }

public void setLoginLogDao(LoginLogDao loginLogDao){ this.loginLogDao=loginLogDao; }

public boolean hasMatchUser throws Exception(String userName, String password){ int matchCount=userDao.getMatchCount(useName, password); return matchCount>0; }

public User findUserByUserName throws Exception (String userName){ return userDao.findUserByUserName(userName); }

public void loginSuccess throws Exception (User user){ user.setCredits(5+user.getCredits()); LoginLog loginLog=new LoginLog(); loginLog.setUserId(user.getUserId()); loginLog.setIp(user.getLastIp());

loginLog.setLoginDate(user.getLastVisit()); userDao.updateLoginInfor(user);

loginLogDao.insertLoginLog(loginLog); } }

其中hasMatchUser(),findUserByUserName(),loginSuccess()需要的事务管理需求描述如下:

hasMatchUser():只读事务,事务传播方式必须有事务管理,隔离级别是不能出现脏读,出现SQLException需要回滚。

findUserByUserName():只读事务,事务传播方式可以没有事务管理,隔离级别是不能出现脏读,出现任何Exception不需要回滚。

loginSuccess():可写事务,事务传播方式是强制方式,隔离级别是不能出现脏读,出现任何Exception需要回滚。

(1) 写出该业务类使用注解来实现事务管理的完整形式。

(2) 写出该业务类使用Schema XML方式来实现事务管理的完整形式(填入下面即可)。

xsi:schemaLocation=\

http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-2.0.xsd\

本文来源:https://www.bwwdw.com/article/p7hd.html

Top