學習中遇到問題--記錄

異常

1.spring依賴於日誌

異常:

Java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
解決:加入commons-logging-1.1.3.jar

2.

異常:

java.lang.IllegalStateException: BeanFactory not initialized or already closed - call ‘refresh’ before accessing beans via the ApplicationContext
解決:
ApplicationContext ctx = new ClassPathXmlApplicationContext();
改爲ApplicationContext ctx = new ClassPathXmlApplicationContext(“beans.xml”);
其中beans.xml是spring bean的配置文件

3.spring2.5

異常:
Error creating bean with name ‘userService’: Autowiring of methods failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.mashibing.service.UserService.setUserDao(com.mashibing.dao.UserDao); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.mashibing.dao.UserDao] is defined: Unsatisfied dependency of type [interface com.mashibing.dao.UserDao]: expected at least 1 matching bean
解決:
設置自動注入(@Autowired )的bean(setUserDao)沒有在xml文件中定義

4.

異常:
error at ::0 can’t find referenced pointcut performance
解決:
如果要使用AspectJ完成註解切面需要注意下面的JDK與AspectJ的匹配:
  JDK1.6 —— aspectJ1.6
  JDK1.7 —— aspectJ1.7.3+

5.

異常:
cannot proxy target class because CGLIB2 is not available
解決:
加入CGLIB2的包cglib-nodep-2.1_3.jar
注:
一個類若實現了接口,會用jdk自帶的proxy和invocationhandler來產生代理;若沒有實現接口,會採用直接操作二進制碼的方式(即CGLIB)來幫你產生代理的代碼

6.

異常:
nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPoo
解決:
加入commons-pool.jar

7.

異常:
Cannot load JDBC driver class ‘com.mysql.jdbc.Driver’
解決:
缺少驅動,加入mysql驅動

8建立maven工程報錯

異常:
Could not resolve archetype org.apache.maven.archetypes:maven-archetype-quickstart:RELEASE from any of the configured repositories
解決:
將本地maven倉庫中maven-archetype-quickstart文件夾全部刪除,再重新建立maven工程,會自動重新下載

9.maven工程測試連接mysql數據庫

異常:
Error creating bean with name ‘dataSource’ defined in class path resource [conf/dbconfig.xml]: Invocation of init method failed; nested exception is java.sql.SQLException: com.mysql.jdbc.Driver
解決:
驅動沒有加載進來,maven工程pom.xml中加入依賴mysql

10.

異常:
generate mybatis config執行後生成bean類報錯alias cannot resolved to a type
解決:
缺少mybatis包,maven工程加入依賴

11.

異常:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): ….TTestMybatisMapper.selectByPrimaryKey
解決:
Mapper.xml文件中mapper namespace定義錯誤

發佈了26 篇原創文章 · 獲贊 10 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章