spring使用中報Cannot proxy target class because CGLIB2 is not available錯
發現問題
public interface StudentService
{
void add();
}
@Service
public class StudentServiceImpl implements StudentService
{
void add(){ }
}
public class StudentAction extends ActionSupport
{
private StudentService studentService;
@Resource
public void setStudentService()
{
}
}
以上描述了一個很簡單的注入過程。但若StudentServiceImpl沒有實現StudentService接口
@Service
public class StudentServiceImpl
{
void add(){ }
}
在使用的時候會報Cannot proxy target class because CGLIB2 is not available
問題原因
代理為控製要訪問的目標對象提供了一種途徑。當訪問對象時,它引入了一個間接的層。JDK自從1.3版本開始,就引入了動態代理,並且經常被用來動態地創建代理。JDK的動態代理用起來非常簡單,但它有一個限製,就是使用動態代理的對象必須實現一個或多個接口。
解決辦法
方案一 使實際的類實現某個接口
方案二 使用CGLIB包
cglib是一個開源項,一個強大的,高性能,高質量的Code生成類庫,它可以在運行期擴展Java類與實現Java接口。Hibernate用它來實現PO字節碼的動態生成。
參考地址:https://baike.baidu.com/view/1254036.htm
最後更新:2017-04-03 05:40:25
上一篇:
oracle中兩表之間值互相插入和表自身插入值
下一篇:
SQL語句中where 1=1的基本用法
nagios報錯:.stdio.h4561 error 'gets' undeclared here (not in a function)
你有什麼理由還不選擇阿裏雲服務器呢–從阿裏雲發布自研商用關係型數據庫POLARDB想到的
CentOS創建mysql數據庫定時備份壓縮刪除
騰訊雲:數據庫春節不崩潰,黃金14天是關鍵
為什麼要把jsp放在WEB-INF目錄下
專訪實戰專家,揭秘iOS神奇開發之路
Docker容器雲在金融行業的應用
Redis開發運維實踐開發者設計規範之客戶端推薦
ANDROID打開係統設置或信息界麵
SpringBoot開發案例之整合定時任務(Scheduled)