Eclipse、Tomcat、Spring3等使用过程的一些配置、错误等的总结记录

背景:
公司项目使用jdk1.6、tomcat7、SVN、Spring3,本文总结使用到现在的一些配置和问题。

一、配置

1、Eclipse项目几点配置:

(1)Windows -> Preferences -> Java/Installed JREs:
JRE home: C:Program Files (x86)Javajdk1.6.0_33
JRE name:jdk1.6.0_33
(2)底部视图加上Ant
Winodws -> Show View -> Other.. -> Ant -> OK -> 把项目build.xml拖到Ant上。
2、配置Tomcat服务器

(1)Windows-> Preferences -> Server -> Runtime Environment -> Add -> Apache Tomcat v7.0 -> E:javatoolapache-tomcat-7.0.82
(2)servers标签页新建Server -> Apache Tomcat v7.0 -> Finish
(3)双击(b)建立的Server,在里面的Server Locations区域里面选择第2个单选:Use Tomcat installation(takes control of Tomcat installation)保存。

3、Eclipse里安装SVN插件

(1)下载SVN插件
http://subclipse.tigris.org/servlets/ProjectDocumentList?folderID=2240
下载里面的“site-1.8.22.zip ”,下载后的插件包目录结构:

features (目录)
plugins (目录)
artifacts.jar
content.jar
index.html
site.xml

(2)将插件包features和plugins目录中的文件分别复制到Eclipse安装目录的features和plugins中,然后重启Eclipse
(3)如果本地还没有项目,从svn获取代码:
File -> Import -> Svn -> 从Svn检出项目 -> [这里填写实际SVN地址]
如果本地已经有之前项目,SVN会自动绑定。

4、Eclipse中修改SVN用户名和密码

来源:http://www.cnblogs.com/exmyth/p/4446665.html
(1)查看你的Eclipse 中使用的是什么SVN Interface
windows > preference > Team > SVN > SVN Interface
(2)如果是用的JavaHL, 找到以下目录并删除auth目录下的文件.
Windows 7
C:Users"你的用户名"AppDataRoamingSubversionauth
XP
C:Documents and Settings"你的用户名"Application Data(隐藏文件夹)"Subversionauth"
(3) 如果你用的SVNKit, 找到以下目录并删除.keyring文件.
[eclipse ]"configuration"org.eclipse .core.runtime

5、SVN忽略classes、release、bin

(1)打开repository browser(在资源管理器中输入svn:\,回车后输入URL地址),删除里面classes、release的子目录
(2)删除本地电脑里面classes、release的子目录所有文件,右键点击这些子目录,team -> 添加至svn:ignore。
(3)Eclipse ->window->preferences->team->Ignored Resource->Add Pattern->
如忽略realse文件夹,就Add Pattern,填入*/realse/*
如忽略bin文件夹,就Add Pattern,填入*/bin/*
如忽略.class类型文件,填入*.class

6、Eclipse配置Activi插件

https://blog.csdn.net/qq_23888451/article/details/83180874 下载插件
(1)将下载好的jars文件夹里的3个jar文件复制到eclipse安装目录的plugins目录下。并删除eclipse安装目录下,configuration文件夹里的org.eclipse.update文件夹,启动eclipse。
(2)打开eclipse,在Help->Install New Software后的弹出窗点击Available Software Sites,删除以前安装失败的资源信息。
(3)点击Add,点击local…,选择本地的解压缩activiti-designer-5.14.1文件夹,一路next,finish,成功。

二、问题

1、eclipse调试时断点频繁停在threadpoolexecutor
解决:
Eclipse->Window->Preferences->Java->Debug,去掉"Suspend execution on uncaught exceptions"

2、eclipse导入项目以后,内容没有错误,项目上却有个小红叉
解决:
Problems选项卡会有详细的错误描述,如果被关闭了的话,重新打开方法:
Eclipse->Window->Show View->Other->Problems。

3、错误提示:The method of type must override asuperclass
解决:
Windows->Preferences->Java->Compiler,在右边的Compiler compliance level 修改版本为 1.6
项目右键->build path->configure build path->java Compiler->Compiler compliance level 修改版本为 1.6

4、错误提示:Java compiler level does not match the version of the installed Java project facet
解决:
右键项目Properties->Properties->Project Facets->Project Facets->“Java”下拉列表中选择相应版本

5、eclipse调试时出现source not found。
解决:在debug时出现的那个 Source not found 的 下面有个 Edit Source Lookup Path....
点击这个按钮,---add--java Project---添加上当前项目即可

6、tomcat出现异常java.lang.OutOfMemoryError 

(1)PermGen space
打开tomcat的bin目录里面的catalina.bat编辑,
在文件开头或者echo Using CATALINA_BASE的上面一行加上

set JAVA_OPTS=-server -XX:PermSize=512m -XX:MaxPermSize=1024m

(2)Java heap space
打开tomcat的bin目录里面的catalina.bat编辑,加上-Xms2048m -Xmx2048m

set JAVA_OPTS=-server -XX:PermSize=512m -XX:MaxPermSize=1024m -Xms2048m -Xmx2048m

7、tomcat出现异常Name [testDB] is not bound in this Context.Unable to find [testDB].
conf/context.xml已经配置Oracle数据源
<Resource auth="Container" driverClassName="oracle.jdbc.OracleDriver" loginTimeout="10" maxWait="5000" name="testDB" password="dev" testOnBorrow="true" type="javax.sql.DataSource" url="jdbc:oracle:thin:@127.0.0.1:1521:testdb" username="dev"/>
后来发现在spring配置文件中引用testDB时,应该前面加上java:comp/env/,即java:comp/env/testDB,问题解决。
看网上说WEB-INF里的web.xml文件还要配置如下信息

<resource-ref>
<description>jdbc/oracleds</description>
<res-ref-name>testDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

经过测试,不知是否项目用的是Spring关系,上面这段不需要配置。

另外,可以新建个jsp测试文件来看数据库是否连接得上。(WEB-INFlib需要引用数据库驱动包,如本机ojdbc14.jar)

<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<sql:query var="rs" dataSource="testDB">
select code,name from tb where rownum < 5
</sql:query>
<html>
<head>
<title>DB Test</title>
</head>
<body>
<h2>Results</h2>
<c:forEach var="row" items="${rs.rows}">
code: ${row.code}<br/>
name: ${row.name}<br/>
</c:forEach>
</body>
</html>

8、Spring Mvc报错:Content type 'application/json;charset=UTF-8' not supported

控制器接口:

@RequestMapping(value = "/test", method = RequestMethod.POST)
@ResponseBody
public String test(@RequestBody UserDTO userDTO) {
  //...
}

Postman请求json数据报错:Content type 'application/json;charset=UTF-8' not supported

解决方法:

(1)在Spring配置中缺少了

<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">                
</bean>
加上去如下:
    <bean name="annotationHandlerMapping" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="mappingJacksonHttpMessageConverter" />
                <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">                
                </bean>
            </list>
        </property>
    </bean>
    
    <bean id="mappingJacksonHttpMessageConverter"
        class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>text/html;charset=UTF-8</value>
            </list>
        </property>
    </bean>

(2)项目需要有jackson-annotations、 jackson-core、jackson-databind这3个jar包。

三、Eclipse几个常用快捷键

查找内容:ctrl + h
查找文件:ctrl + shift + r
格式化代码:ctrl + shift + F
添加“/”注释:ctrl + /
添加“/**/”注释:ctrl + shift + /
删除行:ctrl + d
竖向选择(开启、关闭):alt + shift + a
重命名方法等:alt + shift + r
原文地址:https://www.cnblogs.com/gdjlc/p/7026760.html