Spring注解配置、Spring aop——Spring学习 day2

注解配置:

1.为主配置文件引入新的命名空间(约束)

preference中引入文件

2.开启使用注解代理配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd ">
<context:component-scan base-package="com.littlepage.entity"></context:component-scan>
</beans>

3.类表名注解

//相当于xml文件配了bean的name为user

@Component("user")//entity层
@Service("user")//service层
@Controller("user")//web层
@Repository("user")//dao层

四个注解一样,但是可以根据注解名字可以了解功能

@Scope("singlenton")

scope功能在上一篇博客中讲过

@Autowared

自动找到相应类

4.运行

sts插件:

1.手动安装(成功率低)

2.使用老师的Eclipse(我选用)

3.spring装好插件的eclipse

Spring与Junit整合测试:

Spring的AOP:

猜你喜欢

转载自www.cnblogs.com/littlepage/p/10858680.html
今日推荐