在Spring MVC中的配置中一般會(huì)遇到這兩個(gè)標(biāo)簽,作為<context:component-scan>的子標(biāo)簽出現(xiàn)。
但在使用時(shí)要注意一下幾點(diǎn):
1.在很多配置中一般都會(huì)吧Spring-common.xml和Spring-MVC.xml進(jìn)行分開(kāi)配置,這種配置就行各施其職一樣,顯得特別清晰。
在Spring-MVC.xml中只對(duì)@Controller進(jìn)行掃描就可,作為一個(gè)控制器,其他的事情不做。
在Spring-common.xml中只對(duì)一些事務(wù)邏輯的注解掃描。
2.現(xiàn)在給定一個(gè)項(xiàng)目包的機(jī)構(gòu):
com.fq.controlller
com.fq.service
就先給定這兩個(gè)包機(jī)構(gòu)
(1)在Spring-MVC.xml中有以下配置:
<!-- 掃描@Controller注解 -->
<context:component-scan base-package="com.fq.controller">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
可以看出要把最終的包寫(xiě)上,而不能這樣寫(xiě)base-package=”com.fq”。這種寫(xiě)法對(duì)于include-filter來(lái)講它都會(huì)掃描,而不是僅僅掃描@Controller。哈哈哈,這點(diǎn)需要注意。他一般會(huì)導(dǎo)致一個(gè)常見(jiàn)的錯(cuò)誤,那就是事務(wù)不起作用,補(bǔ)救的方法是添加use-default-filters=”false”。
(2)在Spring-common.xml中有如下配置:
<!-- 配置掃描注解,不掃描@Controller注解 -->
<context:component-scan base-package="com.fq">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
可以看到,他是要掃描com.fq包下的所有子類,不包含@Controller。對(duì)于exculude-filter不存在包不精確后都進(jìn)行掃描的問(wèn)題。
在Eclipse中創(chuàng)建Maven的Web項(xiàng)目時(shí)出現(xiàn)錯(cuò)誤:An internal error occurred during: “Retrieving archetypes:”. Java heap space,可以通過(guò)以下步驟來(lái)解決問(wèn)題。
1. 找到Eclipse的根目錄下的eclipse.ini(或myeclipse.ini)文件并打開(kāi)
2.修改文件中的以下配置
-Dosgi.requiredJavaVersion=1.5(可選)
-Xms512m
-Xmx1024m
這是我的配置,大家可以嘗試著修改下,不同的機(jī)器配置可能支持的情況不同。
版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。
myeclipse自定義java注釋:
Window->Preference->Java->Code Style->Code Template
然后展開(kāi)Comments節(jié)點(diǎn)就是所有需設(shè)置注釋的元素
-----------------
文件 (Files) 注釋標(biāo)簽:
/**
* @Project : ${project_name}
* @Title : ${file_name}
* @Package ${package_name}
* @Description : ${todo}
* @author shenyanghong ahong2011@gmail.com
* @date ${date} ${time}
* @Copyright : ${year} www.1000chi.com Inc. All rights reserved.
* @version V1.0
*/
類 (Types) 注釋標(biāo)簽(類的注釋):
/**
* @ClassName ${type_name}
* @Description ${todo}
* @author shenyanghong ahong2011@gmail.com
* @date ${date}
* ${tags}
*/
字段 (Fields) 注釋標(biāo)簽:
/**
* @Fields ${field} : ${todo}
*/
構(gòu)造函數(shù)標(biāo)簽:
/**
* <p>Title: </p>
* <p>Description: </p>
* ${tags}
*/
方法 (Constructor & Methods) 標(biāo)簽:
/**
* @Title: ${enclosing_method}
* @Description: ${todo}
* @param ${tags} 設(shè)定文件
* @return ${return_type} 返回類型
* @throws
*/
覆蓋方法 (Overriding Methods) 標(biāo)簽:
/* ( 非 Javadoc)
* <p>Title: ${enclosing_method}</p>
* <p>Description: </p>
* ${tags}
* ${see_to_overridden}
*/
代表方法 (Delegate Methods) 標(biāo)簽:
/**
* ${tags}
* ${see_to_target}
*/
getter 方法標(biāo)簽:
/**
* @return ${bare_field_name}
*/
setter 方法標(biāo)簽:
/**
* @param ${param} 要設(shè)置的 ${bare_field_name}
*/