java Bug

<1> org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.OutOfMemoryError: PermGen space

 

answer:

1.Just an expanded version of Bogdan's answer

1. At the Main menu go to Window -> Show View -> Servers
2. At the 'Servers' View double click on 'Tomcat'
3. A Tomcat Overview page will be opened
4. Find 'General Information' section and click on 'Open launch configuration'
5. At the 'Edit Configuration' popup go to Arguments tab
6. Find 'VM arguments' section and place -Xmx1024m -XX:MaxPermSize=512m there

 

 

2.tomcat catalina.bat or catalina.sh.

set JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG% -Xms512m -Xmx512m -XX:PermSize=512m -XX:MaxPermSize=1024m

 

 

<2>.org.xml.sax.SAXNotRecognizedException: http://javax.xml.XMLConstants/feature/secure-processing

        java.lang.IllegalStateException: org.xml.sax.SAXNotRecognizedException: Feature 'http://javax.xml.XMLConstants/feature/secure-processing' is not recognized.

 

answer:

     Upgrade your xercesImpl jar file located in lib folder to xercesImpl 2.9.1. You can simply download it and replace it. It must work. Thanks。

      在项目中,直接在pom.xml中移除这个xercesImpl.jar后,maven能够install了

  <dependency>
<groupId>net.gplatform</groupId>
<artifactId>sudoor-server-lib</artifactId>
<version>1.0.4-SNAPSHOT</version>
<exclusions>
    <exclusion>
       <groupId>xerces</groupId>
      <artifactId>xercesImpl</artifactId>
   </exclusion>
</exclusions>
</dependency>

 

这个问题在http://angelina.iteye.com/blog/1920234也有出现。

 

 

<3>

Archive for required library: 'C:/Users/d01/.m2/repository/commons-beanutils/commons-beanutils/1.9.2/commons-beanutils-1.9.2.jar' in project 'obiz' cannot be read or is not a valid ZIP file

 

  直接去掉C:/Users/d01/.m2/repository/commons-beanutils/commons-beanutils下面的文件,再进行maven操作

 

 

    <4>

org.apache.cxf.interceptor.Fault: No binding operation info while invoking unknown method with params unknown.

 

webservice缺少?wsdl后缀

 

     <5>

Failure to transfer org.codehaus.plexus:plexus-archiver:jar:2.0.1 from http://repo.maven.apache.org/
 maven2 was cached in the local repository, resolution will not be reattempted until the update interval 
 of central has elapsed or updates are forced. Original error: Could not transfer artifact 
 org.codehaus.plexus:plexus-archiver:jar:2.0.1 from/to central (http://repo.maven.apache.org/maven2): 
 No response received after 60000
复制代码
复制代码
 Failure to transfer org.codehaus.plexus:plexus-io:pom:1.0 from http://repo.maven.apache.org/maven2 
 was cached in the local repository, resolution will not be reattempted until the update interval of 
 central has elapsed or updates are forced. Original error: Could not transfer artifact 
 org.codehaus.plexus:plexus-io:pom:1.0 from/to central (http://repo.maven.apache.org/maven2): No 
 response received after 60000
复制代码

上面的两个错误描述解决步骤是一样的,就不罗嗦重复介绍了。

以第二种错误提示为例:

1.先去掉Maven工程的maven特性,选中工程 鼠标右键-->Maven-->Disable Maven Nature. 此步骤后pom.xml错误消失

2.为工程增加Maven特性,选中工程 鼠标右键-->Configure-->Convert to Maven Project.

经过上述步骤,Maven工程就正常了。

PS:网络不好的情况下,用Maven真是不爽,最好建立本地私服。

 

 

<6>

WARNING: No mapping found for HTTP request with URI [/mvc/user/findUser/lisi/770] in DispatcherServlet

with name 'springMVC'

可能是没有配置<mvc:annotation-driven />的原因。

 

 

<7>

java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.

 

 

from:http://stackoverflow.com/questions/24025924/java-lang-illegalstateexception-no-thread-bound-request-found-exception-in-asp

 

You shouldn't autowire a HttpServletRequest in your aspect as this will tie your aspect to be only runnable for classes that are called from within an executing HttpServletRequest.

Instead use the RequestContextHolder to get the request when you need one.

 

private String getRemoteAddress() {
    RequestAttributes attribs = RequestContextHolder.getRequestAttributes();
    if (attribs instanceof NativeWebRequest) {
        HttpServletRequest request = (HttpServletRequest) ((NativeWebRequest) attribs).getNativeRequest();
        return request.getRemoteAddress();
    }
    return null;
}

 

 

 

<8> BigDecimal转换为Json发生截断

Java返回处理很长的数据时,通常用BigDecimal来获取Long不能获取的值。但是当我们把BigDecimal的值付给map然后以json格式返回给前端时就会生错误。

 

1.错误的示例如下:

Map<String,Object>map=new HashMap<String,Object>();

map.put("id",new BigDecimal("123456789"));

return json(map);

当转换为json数据时,{"id":123457000},id的值和原来的BigDecimal值不等。如果再用前端获取的值来反查数据数据时就会有问题,因为id值并不等于原来的123456789!

2.那这个问题是怎么产生的呢?其实是由于js对数据进行处理的时候,对数据进行了截断。要正确的处理,那么可以通过显示的把BigDecimal转化为String类型,在转化为json数据传给前端就ok了!

来看看具体用法吧:

Map<String,Object>map=new HashMap<String,Object>();

map.put("id",String.valueOf(new BigDecimal("123456789")));

return json(map);

 

通过String的valueOf方法显示的把值转化为String类型,就能避免前端的数据值截断问题了

 

注意事项:数据值传给前端值时最好显示转化为String类型

 

<9> Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '' for column 'createtime' at row 1...

 

 

因为在测试服务器上该项目是正常的,所以比较纳闷,项目是一样的都是hibernate3.6,那就是JDK版本,MySQL版本,还有Tomcat版本不一样导致。最终排除其它,锁定在MySQL版本问题上,我在测试上用的是5.1版本,服务器上使用的是最新的5.6版本;看到网上说5.6对时间类型做了调整,于是果断换成5.5的Mysql64位。测试,通过,正常。

所以,遇见该问题解决方法,目前是换数据库版本,因为是5.6版本比较新,我在网上还没有找到什么解决方案,如果哪位高手有更好的解决方案,请下面留言,大家一起学习,共同进步。

---------------------------------------------

事隔多日,回看这个问题,自己又在工作中遇见该问题,所以将此问题按照楼下大侠的指导修改了一下,验证,该解决方案正确

 

解决方法如下:

找到你项目中的mysql-connector-java的架包

将此更新到最新版本,我目前项目使用的环境是:java7,

使用的jar包是:mysql-connector-java-5.1.31.jar

经过我的测试没有问题。

如果你的环境是java6,这个jar也是可以的。

 

完成

 

----------------------------------------------------

   经过在网上一番搜索,最终找到了问题解决方案: 更新 mysql-connector-java.jar 到较新版本, 于是我将该 jar 包由原来的 5.0.4 更新到 5.1.27,更新后重启服务,结果悲剧了,查询的时候报错了,提示“column 'ID' not found...”, 说是 ID 字段找不到,但数据库的结构从来没有修改过,该字段也确确实实是存在的,所以可以肯定这个问题的产生是因为刚才更新了 mysql-connector-java.jar 包造成的,于是乎继续搜索问题解决方案, 还真有人遇到和我一样的问题了, 说是只需在 jdbc.url 后面加上“&useOldAliasMetadataBehavior=true” 即可, 赶紧试试,  经验证还真是这个问题, 而且之前的那日期字段的问题也不再出现了,问题完美解决!

 

你可能感兴趣的:(java)