日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring自动扫描配置及使用方法

發(fā)布時間:2023/11/29 javascript 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring自动扫描配置及使用方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

2019獨角獸企業(yè)重金招聘Python工程師標準>>>

首先,檢查一下你lib下有沒有 common-annotations.jar 這個jar包 沒有的話要導(dǎo)入工程。

下一步配置spring的配置文件applicationContex.xml,加入命名空間

紅色為需要添加的內(nèi)容

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context ">http://www.springframework.org/schema/context/spring-context-2.5.xsd><context:component-scan base-package="你要掃描那個包(例如com.myprogram)" annotation-config="true"/>

這句話的意思時,當啟動服務(wù)器的時候spring自動掃描你設(shè)置掃描的包下面的添加注解了的類

例如

服務(wù)層service定義接口和接口實現(xiàn)類

接口

public interface UsersLogsService {public abstract void delete(UsersLogs persistentInstance); }

實現(xiàn)類

@Service("UsersLogsService")//注解項 public class UsersLogsServiceImpl implements UsersLogsService {public void delete(UsersLogs persistentInstance) {}}

控制層下的某個Action,

//自己定義需要注意的是"/loginAction"要與你的struts-config.xml配置文件中映射action的path一致

@Controller("/loginAction")//注解項 public class LoginAction extends DispatchAction {//通過Resource注解我們就可以獲得剛才注解了的UsersLogsService實例調(diào)用他的方法@Resource(name="UsersLogsService") private UsersLogsService usersLogsService;public ActionForward checkLogin(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {return null;}}

到此位置,配置的流程就是這樣,Dao數(shù)據(jù)操作層我沒有寫,創(chuàng)建Dao添加注解

服務(wù)層調(diào)用Dao就像上面控制層調(diào)用服務(wù)層一樣,只要上面流程弄明白了,那么恭喜你,spring自動掃描的技術(shù)你也就學會了。

轉(zhuǎn)載于:https://my.oschina.net/longtutengfei/blog/164741

總結(jié)

以上是生活随笔為你收集整理的Spring自动扫描配置及使用方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。