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>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值