java入門常見問題

1、No result defined for and validate 驗證錯誤

      注意仔細觀察錯誤描述, 有可能是action命名空間不正確,是否前面忘記加  / 。

2、Unterminated <s:property tag XXX  (13,15)

       注意13行可能有非法字符。

3、tomcat服務器,工程中maven依賴已經設置好,調試運行,提示找不到org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

       選擇tomcat下應用,重新配置解決。

4、異常:com/opensymphony/xwork2/spring/SpringObjectFactory.java:209:-1

       參考http://blog.163.com/wzx_dd/blog/static/194285072201263011524768/

       使用spring,但未添加監聽器,web.xml增加以下內容即可

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

5、This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag

       參考http://0411.iteye.com/blog/1071442

      使用struct2標籤,但過濾模式爲*.action,web.xml中將 <url-pattern>*.action</url-pattern> 改爲<url-pattern>/*</url-pattern>即可

6、貌似spring未加載xml配置文件中的bean時,bean屬性未被注入,但是未提示錯。

       原因:定義bean時 後面添加了singleton="false", 而我使用的spring版本是3.0.1。spring2.5之前用 singleton=“false“;2.5或更新版本用scope="singleton"。導致該bean裏面的bean屬性未被注入。

 7、SSH框架,action類注入的bean屬性和執行方法時bean屬性id不一致。

       原因:struts.xml中action定義時 class屬性值不是bean。

8、maven依賴的jar包沒有發佈到lib目錄

       原因:pom.xml文件中依賴的jar包中有 <scope>provided</scope>,意思是隻在編譯時使用該庫,發佈時不發佈,導致問題出現。

9、Failed to start component [StandardEngine[Catalina].StandardHost****

       原因:tomcat關聯的jdk版本比較低, 工程使用的版本比較高


10、jetty 加載包含spring的web,報ClassNotFoundException異常,找不到ContextLoaderListener類

        原因:web-inf的lib目錄下,我增加了spring目錄用以存放spring的jar包導致,把spring目錄的jar包,移到上一級lib目錄下,編譯通過。log4j卻可以放在lib的子目錄中,不會報找不到類的錯誤。

11、@Controller註解的bean沒有自動加載

      原因: spring的配置xml文件中 未加載對註解方式的支持。

      解決方案: 在applicationContext.xml文件頭加入xmlns:context="http://www.springframework.org/schema/context"

     內容中加入

      <context:annotation-config />
      <context:component-scan base-package="com.suma" />

     完成自動註解配置


12. junit測試時Resources.getResourceAsStream的路徑問題

     我在寫自測用例時,用到這個函數來加載ibatis的xml文件

     

   調用 Resources.getResourceAsStream加載MonitorData.xml文件,總是加載不上

   通過IpqamAutoMonitorDAOTest.class.getClassLoader().getResource("");獲取當前路徑url,獲悉Resources.getResourceAsStream的根目錄是classes目錄。

  而該classes目錄是在eclipse建立過程時buildpath的輸出目錄中指定的。


13.  SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); 總是失敗問題。

       我這邊問題原因,是ibatis的配置xml和mapper的xml注意xml擡頭是不一致的,不能混用

      config: <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">

  mapper: <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

14. 使用xml加mapper接口方式實例的ibatis對象, 使用@Autowired註解方式注入對象時,注意在spring配置文件中加載如下bean

  1. <!-- 轉換器  MapperScannerConfigurer會把com.suning.schema.mabatisInterface下的包進行掃描 獲取接口,通過代理創建Bean實例給Sp                ring進行管理-->  
  2.     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
  3.         <property name="basePackage" value="com.suning.schema.mabatisInterface" />   
  4.     </bean>    


15. conflicts with existing, non-compatible bean definition of same name and class 問題, 檢查自己寫的代碼並沒有存在相同名稱的bean

       原因,工程使用了myibatis的mapper接口和xml自動生成實例的功能,下面代碼中value的值包含的包範圍過大,導致mapper自動爲接口生成了實例類

  1. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  2. <property name="basePackage" value="com.suma.product.ipqamtest.dao" />
  3. </bean>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章