spring IOC 搭建

操作步骤

 

1、添加jar包

<!-- spring -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>4.1.6.RELEASE</version>
</dependency>

2、新建 applicationContext.xml文件

    2.1 如果使用扫描+注解的方式,需要在xml文件中配置需要扫描的类

<context:component-scan base-package="com.nut.dao"></context:component-scan>

3、在需要扫描的类上加注解

    3.1在类名上加下面四个注解

@Component  //搞不清用这个

@Repository  //在dao层

@Service  //在service层

@Controller  //在control层

 3.2在需要扫描的变量名上加下面注解

@Resource

 

4、使用监听器启动sprig的配置文件

    

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applictionContext.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值