当前位置:首页 > Spring笔试考试题目
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\
共分享92篇相关文档