spring面试题

1. IOC:依赖注入/控制反转;通过XML的配置方式解耦模块之间的关系;(举例,new--工厂--IOC)

2. 3种注入方式:set注入,构造方法注入,接口注入

3. 集合注入/简单属性注入

<bean name="userDAO" class="com.bjsxt.dao.impl.UserDAOImpl">
  	<property name="daoId" value="8"></property>
  	<property name="daoStatus" value="good"></property>
  </bean>

<beanname="userDAO" class="com.bjsxt.dao.impl.UserDAOImpl">

         <propertyname="sets">

                 <set>

                         <value>1</value>

                         <value>2</value>

                 </set>

         </property>

         <propertyname="lists">

                 <list>

                         <value>1</value>

                         <value>2</value>

                         <value>3</value>

</list>

  </bean>

4. 作用域 Scope

<beanid="userService" class="com.bjsxt.service.UserService"scope="prototype">
         <propertyname="userDAO" ref="u" />
  </bean>

  1. Singleton,单例
  2. prototype,每次new一个新的


5. 自动装配:不用手动配置依赖关系,按一定的规则自动寻找依赖的bean(byName/byType...)


6. bean的生命周期:singleton的bean由applicationContext容易管理,可配置ini-method,destroy-method


7. resource接口:读取各种资源文件,不同的资源文件类型有不同的实现


8. 简化XML:模板继承,引入标签


9. AOP:面向切面编程,不同模块间交叉关注点的问题;事物,日志,缓存,安全检查等

@Aspect
@Component
public class LogInterceptor {
	//公用切面实现
	@Pointcut("execution(public * com.bjsxt.service..*.add(..))")
	public void myMethod(){};
	
	//调用公用切面
	@Before("myMethod()")
	public void before() {
		System.out.println("method before");
	}
	
	//环绕方法,需要指明方法前后的逻辑
	@Around("myMethod()")
	public void aroundMethod(ProceedingJoinPoint pjp) throws Throwable {
		System.out.println("method around start");
		pjp.proceed();
		System.out.println("method around end");
	}
	
}

10. 实现方式:aspectJ,编译器增加,在生成class文件时已增强了方法;动态代理,运行期增强(JDK实现/cglib)

11. JDK动态代理实现:实现InvocationHandler接口,重写invoke方法,通过Proxy.newProxyInstance()方法获取代理对象

12. 申明式的事物管理

<bean id="txManager"
	class="org.springframework.orm.hibernate3.HibernateTransactionManager">
	<property name="sessionFactory" ref="sessionFactory" />
</bean>
<aop:config>
	<aop:pointcut id="bussinessService"
		expression="execution(public * com.bjsxt.service..*.*(..))" />
	<aop:advisor pointcut-ref="bussinessService"
		advice-ref="txAdvice" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="txManager">
	<tx:attributes>
		<tx:method name="getUser" read-only="true" />
		<tx:method name="add*" propagation="REQUIRED"/>
	</tx:attributes>
</tx:advice>

13.  与hibernate集成:hibernateTemple(模板)


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值