你的位置:首页 > 软件开发 > Java > Spring框架bean的注解管理方法

Spring框架bean的注解管理方法

发布时间:2017-11-16 20:00:09
首先在原有的jar包:需Spring压缩包中的四个核心JAR包beans 、context、core 和expression下载地址:https://pan.baidu.com/s/1qXLHzAW以及日志jar包commons-logging 和log4j下载地址:https: ...

首先在原有的jar包:

Spring压缩包中的四个核心JAR包

beans 、context、core 和expression

下载地址:

https://pan.baidu.com/s/1qXLHzAW

以及日志jar包

commons-logging 和log4j

下载地址:

https://pan.baidu.com/s/1mimTW5i

再增加一个

spring-aop-5.0.1.RELEASE.jar

 


 

然后,src中建立一个

<??><beans ="http://www.springframework.org/schema/beans" ="http://www.w3.org/2001/ ="http://www.springframework.org/schema/context" xsi:schemaLocation="    >>  <!-- 开启注解扫描 -->  <context:component-scan base-package="com.swift"></context:component-scan></beans>

注解的方法

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

即可,com.swift是包名,最好写上一级,可以扫描到里边所有的包

下边使用注解来创建对象:

package com.swift.user;import org.springframework.stereotype.Component;@Component(value="user")public class User { public String fun() {  return "The User's fun().........."; }}
 

注解创建对象

@Component(value="user")

相当于之前在


 

 

 

 

 



原标题:Spring框架bean的注解管理方法

关键词:Spring

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录