锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 聽聽Author: 姹熷崡鐧借。 聽聽聽聽聽 1.鎵浠ヤ笟鍔″紓甯哥被媧劇敓浜嶣usinessException鍩虹被銆?/p>
聽聽聽聽聽 2.鍘熷垯涓婏紝瑕佽繘琛岀浉鍚屽鐞嗙殑寮傚父鍒嗕負涓綾伙紝鐢‥RROR_CODE鏍囪瘑涓嶅悓銆?/p>
聽聽聽聽聽 3.鍑洪敊淇℃伅緇熶竴鍐欏湪errors.properties錛屼互ERROR_CODE涓轟富閿紝鏀寔i18N錛岀敱鍩虹被鎻愪緵榛樿鐨刧etMessage()鍑芥暟銆?/p>
聽聽聽聽聽 鍙傝傿ussinessException.java鍜孫rderException.java銆?/p>
聽聽 spring-mvc鍙湪xxx-serverlet.xml閲屽畾涔塪efault鍜?鎸塃xcepiton綾誨瀷褰卞皠鐨勯敊璇〉闈? 鍜孲ervlet瑙勮寖姣?涓昏浣滀簡Spring鐗硅壊鐨凧SP璺緞杞悜鍜屾棩蹇楄褰?鍙傝bookstore-servlet.xml 聽聽聽聽聽聽聽聽 error.jsp浼氬悓鏃跺鐞唈sp,servlet,鍜宻pring鎶涜繃鏉ョ殑寮傚父 聽聽聽聽聽聽聽聽 鍏朵腑jsp鐨勫紓甯稿湪exception 鍙橀噺涓? 聽聽聽聽聽聽聽聽 servlet鐨勫紓甯稿湪(Exception)request.getAttribute("javax.servlet.error.exception") 聽聽聽聽聽聽聽聽 spring鐨勫紓甯稿湪(Exception) request.getAttribute("exception") 聽聽聽聽聽聽聽聽 浣跨敤 (String) request.getAttribute("javax.servlet.error.request_uri")鑾峰緱 request_uri Delegates 閫氳繃涓緋誨垪鐨勭敱spring鎵樼鐨刡eans 錛屼唬鐞嗚繃婊よ姹傘?br />FilterChainProxy 閫氳繃鍦╳eb.xml涓畾涔夌殑FilterToBeanProxy 琚姞杞斤紝FilterChainProxy 灝嗕細閫氳繃 It is particularly noted the If a filter name of 聽聽聽 Author: cac 宸矙 聽聽聽 Acegi鏄疭pring Framework 涓嬫渶鎴愮啛鐨勫畨鍏ㄧ郴緇燂紝瀹冩彁渚涗簡寮哄ぇ鐏墊椿鐨勪紒涓氱駭瀹夊叏鏈嶅姟錛屽瀹屽杽鐨勮璇佸拰鎺堟潈鏈哄埗錛孒ttp璧勬簮璁塊棶鎺у埗錛孧ethod 璋冪敤璁塊棶鎺у埗錛孉ccess Control List (ACL) 鍩轟簬瀵硅薄瀹炰緥鐨勮闂帶鍒訛紝Yale Central Authentication Service (CAS) 鑰墮瞾鍗曠偣鐧婚檰錛孹509 璁よ瘉錛屽綋鍓嶆墍鏈夋祦琛屽鍣ㄧ殑璁よ瘉閫傞厤鍣紝Channel Security棰戦亾瀹夊叏綆$悊絳夊姛鑳姐?/p>
瀹樻柟緗戠珯聽聽聽聽 聽http://acegisecurity.sourceforge.net 聽聽聽 Acegi鍙槸瀹夊叏妗嗘灦涔嬩竴錛屽叾瀹炶繕瀛樺湪鍏跺畠浼樼鐨勫畨鍏ㄦ鏋跺彲渚涢夋嫨錛?/p>
<bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
聽聽聽聽聽 <property name="driverClass">
聽聽聽聽聽聽聽 <value>${jdbc.driverClassName}</value>
聽聽聽聽聽 </property>
聽聽聽聽聽 <property name="jdbcUrl">
聽聽聽聽聽聽聽 <value>${jdbc.url}</value>
聽聽聽聽聽 </property>
聽聽聽聽聽 <property name="user">
聽聽聽聽聽 聽<value>${jdbc.username}</value>
聽聽聽聽聽 </property>
聽聽聽聽聽 <property name="password">
聽聽聽聽聽 聽<value>${jdbc.password}</value>
聽聽聽聽聽 </property>
聽聽聽聽聽 <property name="initialPoolSize"><value>10</value></property>
聽聽聽聽聽 <property name="minPoolSize"><value>5</value></property>
聽聽聽聽聽 <property name="maxPoolSize"><value>30</value></property>
聽聽聽聽聽 <property name="acquireIncrement"><value>5</value></property>
聽聽聽聽聽 <property name="maxIdleTime"><value>10</value></property>
聽聽聽聽聽 <property name="maxStatements"><value>0</value></property>
聽聽聽 </bean>
浠ヤ笅鍑犱釜鍙傛暟鏄嬌鐢ㄧ殑鍩烘湰閰嶇疆鍙傛暟錛?br />initialPoolSize錛?
Number of Connections a pool will try to acquire upon startup. Should be between minPoolSize and maxPoolSize
榪炴帴姹犲垵濮嬪寲鏃惰幏鍙栫殑閾炬帴鏁幫紝浠嬩簬minPoolSize鍜宮axPoolSize涔嬮棿
minPoolSize錛?br />Minimum number of Connections a pool will maintain at any given time.
鏈灝忛摼鎺ユ暟
maxPoolSize錛?br />Maximum number of Connections a pool will maintain at any given time.
鏈澶ц繛鎺ユ暟
acquireIncrement錛?br />Determines how many connections at a time c3p0 will try to acquire when the pool is exhausted.
鍦ㄥ綋鍓嶈繛鎺ユ暟鑰楀敖鐨勬椂鍊欙紝涓嬈¤幏鍙栫殑鏂扮殑榪炴帴鏁?br />
maxIdleTime錛?br />Seconds a Connection can remain pooled but unused before being discarded. Zero means idle connections never expire.
鏈澶х┖闂茬殑鏃墮棿錛屽崟浣嶆槸縐掞紝鏃犵敤鐨勯摼鎺ュ啀榪囨椂鍚庝細琚洖鏀?br />
]]>
]]>1.涓氬姟寮傚父綾?/h2>
2.Servlet瑙勮寖閲岀殑寮傚父鎺у埗
聽2.1鎸塭rror-code緇熶竴瀹氫箟閿欒欏甸潰
<error-page>
聽 <error-code>404</error-code>
聽 <location>/404.jsp</location>
</error-page><error-page>
聽 <error-code>500</error-code>
聽 <location>/error.jsp</location>
</error-page>2.2鎸夊紓甯哥被鍨嬪畾涔夊崟鐙敊璇〉闈?/h3>
<error-page>
聽 <exception-type>org.sprngside.bookstore.UserNotFound</exception-type>
聽 <location>/userNotFound.jsp</location>
</error-page>2.3 鍦↗SP閲屽崟鐙畾涔夐敊璇〉闈?/h3>
<@ errorPage="error.jsp">
3.Spring MVC閲岀殑寮傚父鎺у埗
<bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
聽聽聽聽聽聽聽 <property name="defaultErrorView" value="/error.jsp"/>
聽聽聽聽聽聽聽 <property name="exceptionMappings">
聽聽聽聽聽聽聽聽聽聽聽 <props>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <prop key="org.springside.framework.base.BusinessException">/businessError.jsp</prop>
聽聽聽聽聽聽聽聽聽聽聽 </props>
聽聽聽聽聽聽聽 </property>
聽聽聽 </bean>4. error.jsp鐨勫鐞?/h2>
聽聽聽聽聽聽聽聽聽浣跨敤 logger.error(exception.getMessage(), exception); 璁板綍鏁翠釜寮傚父鏍?/p>
java.lang.Object
org.acegisecurity.util.FilterChainProxy
public class FilterChainProxy
Filter
requests to a list of Spring-managed beans. init(FilterConfig)
, destroy()
and doFilter(ServletRequest, ServletResponse, FilterChain)
璋冪敤錛岃皟鐢ㄦ瘡涓涓湪鍏朵腑瀹氫箟鐨勮繃婊ゅ櫒銆?br />
The FilterChainProxy
is loaded via a standard FilterToBeanProxy
declaration in web.xml
. FilterChainProxy
will then pass init(FilterConfig)
, destroy()
and doFilter(ServletRequest, ServletResponse, FilterChain)
invocations through to each Filter
defined against FilterChainProxy
.聽
is configured using a standard
聽聽聽 FilterChainProxy聽 鏄氳繃涓涓爣鍑嗙殑FilterInvocationDefinitionSource 鏉ュ疄鐜伴厤緗殑錛屾瘡涓彲鑳界殑FilterChainProxy搴旇鏈嶅姟鐨刄RI妯″紡閮藉繀欏昏繘鍏?br />聽聽聽聽聽聽聽聽聽聽聽 絎竴涓惌閰嶇殑URI妯″紡灝嗕細琚敤鏉ュ畾涔夊鐞嗚姹傜殑鎵鏈夌殑榪囨護鍣紝灝辨槸璇村彧閫傞厤絎竴緇勮繃婊ゅ櫒錛屽悗闈㈢殑鍏朵粬榪囨護鍣ㄥ皢鏃犳晥銆?br />FilterChainProxyFilterInvocationDefinitionSource
. Each possible URI pattern that FilterChainProxy
should service must be entered. The first matching URI pattern located by FilterInvocationDefinitionSource
for a given request will be used to define all of the Filter
s that apply to that request. NB: This means you must put most specific URI patterns at the top of the list, and ensure all Filter
s that should apply for a given URI pattern are entered against the respective entry. The FilterChainProxy
will not iterate the remainder of the URI patterns to locate additional Filter
s. The FilterInvocationDefinitionSource
described the applicable URI pattern to fire the filter chain, followed by a list of configuration attributes. Each configuration attribute's ConfigAttribute.getAttribute()
corresponds to a bean name that is available from the application context.FilterChainProxy
respects normal handling of Filter
s that elect not to call Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
, in that the remainder of the origial or FilterChainProxy
-declared filter chain will not be called.Filter
lifecycle mismatch between the servlet container and IoC container. As per FilterToBeanProxy
JavaDocs, we recommend you allow the IoC container to manage lifecycle instead of the servlet container. By default the FilterToBeanProxy
will never call this class' init(FilterConfig)
and destroy()
methods, meaning each of the filters defined against FilterInvocationDefinitionSource
will not be called. If you do need your filters to be initialized and destroyed, please set the lifecycle
initialization parameter against the FilterToBeanProxy
to specify servlet container lifecycle management.TOKEN_NONE
is used, this allows specification of a filter pattern which should never cause any filters to fire.
]]>1.1 緗戠珯璧勬簮
璁哄潧聽聽聽聽聽聽聽聽聽聽聽 http://forum.springframework.org/forumdisplay.php?f=33
Jira聽聽聽聽聽聽聽聽聽聽聽聽聽 http://opensource.atlassian.com/projects/spring/browse/SEC1.2 澶氭柟闈㈢殑瀹夊叏鎺у埗綺掑害
聽http://apps:8080/index.htm -> for public
聽http://apps:8080/user.htm -> for authorized user
public void getData() -> all user
public void modifyData() -> supervisor only
order.getValue() < $100 -> all user
order.getValue() > $100 -> supervisor only1.3 闈炲叆渚靛紡瀹夊叏鏋舵瀯
1.4 鍏跺畠瀹夊叏鏋舵瀯
]]>
http://www.springside.org.cn/docs/reference/Acegi2.htm
http://www.springside.org.cn/docs/reference/Acegi3.htm
http://www.springside.org.cn/docs/reference/Acegi4.htm
http://www.springside.org.cn/docs/reference/Acegi5.htm
http://www.springside.org.cn/docs/reference/Acegi6.htm
]]>
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.generic.GenericBeanFactoryAccessor;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ColumnMapRowMapper;
import org.springframework.jdbc.core.ConnectionCallback;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCallback;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.RowCountCallbackHandler;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.StatementCallback;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.samples.petclinic.Person;
/**
聽*
聽* @author worldheart
聽*
聽*/
public class MainTestForJdbcTemplate {
聽private static final Log log = LogFactory.getLog(MainTestForJdbcTemplate.class);
聽
聽public static void main(String[] args) {聽聽
聽聽ListableBeanFactory cbf = new ClassPathXmlApplicationContext("ac1.xml");聽聽
聽聽GenericBeanFactoryAccessor gbfa = new GenericBeanFactoryAccessor(cbf);
聽聽
聽聽JdbcTemplate jt = gbfa.getBean("jdbcTemplate");
聽聽
聽聽jt.execute(new ConnectionCallback(){
聽聽聽public Object doInConnection(Connection con) throws SQLException, DataAccessException {
聽聽聽聽System.out.println(con.getMetaData().getDriverName());
聽聽聽聽return null;
聽聽聽}
聽聽});
聽聽
聽聽List nameList = (List)jt.execute(new StatementCallback(){
聽聽聽public Object doInStatement(Statement stmt) throws SQLException, DataAccessException {
聽聽聽聽System.out.println(stmt.getConnection().getMetaData().getDatabaseProductVersion());
聽聽聽聽List<String> nameList = new ArrayList<String>();
聽聽聽聽ResultSet rs = null;
聽聽聽聽try{
聽聽聽聽聽rs = stmt.executeQuery("select name from types");
聽聽聽聽聽while(rs.next()){
聽聽聽聽聽聽nameList.add(rs.getString("name"));
聽聽聽聽聽}
聽聽聽聽}finally{
聽聽聽聽聽JdbcUtils.closeResultSet(rs);
聽聽聽聽}
聽聽聽聽return nameList;
聽聽聽}
聽聽});
聽聽System.out.println(nameList);
聽聽
聽聽List perList = (List)jt.query("select * from vets",
聽聽聽聽new ResultSetExtractor(){
聽聽聽聽聽聽public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
聽聽聽聽聽聽聽List<Person> personList = new ArrayList<Person>();
聽聽聽聽聽聽聽while(rs.next()){
聽聽聽聽聽聽聽聽Person per = new Person();
聽聽聽聽聽聽聽聽per.setId(rs.getInt("id"));
聽聽聽聽聽聽聽聽per.setFirstName(rs.getString("first_name"));
聽聽聽聽聽聽聽聽per.setLastName(rs.getString("last_name"));
聽聽聽聽聽聽聽聽personList.add(per);
聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽return personList;
聽聽聽聽}
聽聽});
聽聽for(Iterator iterator = perList.iterator(); iterator.hasNext();){
聽聽聽Person person = (Person)iterator.next();
聽聽聽System.out.println(person.getId() + "," + person.getFirstName() + "," + person.getLastName());
聽聽}
聽聽final List<Person> pSonList = new ArrayList<Person>();
聽聽jt.query("select * from vets", new RowCallbackHandler(){
聽聽聽public void processRow(ResultSet rs) throws SQLException {
聽聽聽聽Person per = new Person();
聽聽聽聽per.setId(rs.getInt("id"));
聽聽聽聽per.setFirstName(rs.getString("first_name"));
聽聽聽聽per.setLastName(rs.getString("last_name"));
聽聽聽聽pSonList.add(per);
聽聽聽}
聽聽});
聽聽for(Person pSon: pSonList){
聽聽聽System.out.println(pSon.getId() + "," + pSon.getFirstName() + "," + pSon.getLastName());
聽聽}
聽聽
聽聽RowCountCallbackHandler rcch = new RowCountCallbackHandler();
聽聽jt.query("select * from vets", rcch);
聽聽for(String colName: rcch.getColumnNames())
聽聽聽System.out.println(colName);
聽聽for(int colType: rcch.getColumnTypes())
聽聽聽System.out.println(colType);
聽聽System.out.println(rcch.getColumnCount());
聽聽System.out.println(rcch.getRowCount());
聽聽
聽聽List vetsList = (List)jt.query("select * from vets",
聽聽聽聽new RowMapper(){
聽聽聽聽聽public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
聽聽聽聽聽聽Person pers = new Person();
聽聽聽聽聽聽pers.setId(rs.getInt("id"));
聽聽聽聽聽聽pers.setFirstName(rs.getString("first_name"));
聽聽聽聽聽聽pers.setLastName(rs.getString("last_name"));
聽聽聽聽聽聽return pers;
聽聽聽聽聽}
聽聽});
聽聽System.out.println(vetsList);
聽聽
聽聽ColumnMapRowMapper cmrw = new ColumnMapRowMapper();
聽聽List vList = (List)jt.query("select * from vets", cmrw);
聽聽System.out.println(vList);
聽聽
聽聽System.out.println(jt.queryForInt("select count(*) from vets where id = ?",
聽聽聽聽new Object[]{3}));
聽聽聽聽聽聽
聽聽jt.execute("update owners set address = 'GuangZhou' where telephone = ?",
聽聽聽聽new PreparedStatementCallback(){
聽聽聽聽聽public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
聽聽聽聽聽聽ps.setString(1, "16068008");
聽聽聽聽聽聽ps.addBatch();
聽聽聽聽聽聽ps.setString(1, "6085555487");
聽聽聽聽聽聽ps.addBatch();
聽聽聽聽聽聽return ps.executeBatch();
聽聽聽聽聽}
聽聽});
聽聽
聽聽System.out.println(jt.query("select address from owners where first_name = ? and last_name = ?",
聽聽聽聽new PreparedStatementSetter(){
聽聽聽聽聽public void setValues(PreparedStatement ps) throws SQLException {
聽聽聽聽聽聽ps.setString(1, "Jeff");
聽聽聽聽聽聽ps.setString(2, "Black");
聽聽聽聽聽}
聽聽聽聽},
聽聽聽聽new RowMapper(){
聽聽聽聽聽public Object mapRow(ResultSet rs, int rowNum) throws SQLException {聽聽聽聽聽聽
聽聽聽聽聽聽return rs.getString("address");
聽聽聽聽聽}
聽聽聽聽}));
聽聽
聽聽System.out.println(jt.execute(
聽聽聽聽new PreparedStatementCreator(){
聽聽聽聽聽public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
聽聽聽聽聽聽return con.prepareStatement("select address from owners");
聽聽聽聽聽}
聽聽聽聽},
聽聽聽聽new PreparedStatementCallback(){
聽聽聽聽聽public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
聽聽聽聽聽聽List<String> list = new ArrayList<String>();
聽聽聽聽聽聽ResultSet rs = null;
聽聽聽聽聽聽try{
聽聽聽聽聽聽聽rs = ps.executeQuery();
聽聽聽聽聽聽聽while(rs.next()){
聽聽聽聽聽聽聽聽list.add(rs.getString("address"));
聽聽聽聽聽聽聽}
聽聽聽聽聽聽}finally{
聽聽聽聽聽聽聽JdbcUtils.closeResultSet(rs);
聽聽聽聽聽聽}
聽聽聽聽聽聽return list;
聽聽聽聽聽}
聽聽聽聽}));
聽聽
聽}
}
public class BindStatus
Simple adapter to expose the bind status of a field or object. Set as a variable both by the JSP bind tag and Velocity/FreeMarker macros.
聽 綆鍗曠殑閫傞厤鍣ㄨ幏鍙栧煙鎴栬呮槸瀵硅薄緇戝畾鐘舵侊紝 鍚屾牱閫傜敤浜庢ā鏉褲?br />Obviously, object status representations (i.e. errors at the object level rather than the field level) do not have an expression and a value but only error codes and messages. For simplicity's sake and to be able to use the same tags and macros, the same status class is used for both scenarios.
鏄劇劧錛屽璞$殑鐘舵佽〃紺猴紙渚嬪閿欒鏄璞$駭鐨勮屼笉鏄煙綰у埆鐨勶級娌℃湁琛ㄨ揪寮忔垨鑰呭鹼紝鑰屾槸鍙湁閿欒鐮佸拰娑堟伅
Method Summary | |
---|---|
聽int
|
doEndTag
()
聽聽聽聽聽聽聽聽聽聽聽 |
聽void
|
doFinally
()
聽聽聽聽聽聽聽聽聽聽聽 |
protected 聽int
|
doStartTagInternal
()
聽聽聽聽聽聽聽聽聽聽Called by doStartTag to perform the actual work. |
聽PropertyEditor
|
getEditor
()
聽聽聽聽聽聽聽聽聽聽Retrieve the PropertyEditor for the property that this tag is currently bound to. |
聽Errors
|
getErrors
()
聽聽聽聽聽聽聽聽聽聽Retrieve the Errors instance that this tag is currently bound to. |
聽String
|
getPath
()
聽聽聽聽聽聽聽聽聽聽Return the path that this tag applies to. |
聽String
|
getProperty
()
聽聽聽聽聽聽聽聽聽聽Retrieve the property that this tag is currently bound to, or null if bound to an object rather than a specific property. |
聽boolean
|
isIgnoreNestedPath
()
聽聽聽聽聽聽聽聽聽聽Return whether to ignore a nested path, if any. |
聽void
|
setIgnoreNestedPath
(boolean聽ignoreNestedPath)
聽聽聽聽聽聽聽聽聽聽Set whether to ignore a nested path, if any. |
聽void
|
setPath
(String聽path)
聽聽聽聽聽聽聽聽聽聽Set the path that this tag should apply. |
/**
List perList = (List)jt.query("select * from vets",
聽聽聽聽new ResultSetExtractor(){
聽聽聽聽聽聽public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
聽聽聽聽聽聽聽List<Person> personList = new ArrayList<Person>();
聽聽聽聽聽聽聽while(rs.next()){
聽聽聽聽聽聽聽聽Person per = new Person();
聽聽聽聽聽聽聽聽per.setId(rs.getInt("id"));
聽聽聽聽聽聽聽聽per.setFirstName(rs.getString("first_name"));
聽聽聽聽聽聽聽聽per.setLastName(rs.getString("last_name"));
聽聽聽聽聽聽聽聽personList.add(per);
聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽return personList;
聽聽聽聽}
聽聽});
public interface Mappable {
/**
/**
聽
鎺у埗鍣ㄧ殑姒傚康鏄疢VC璁捐妯″紡鐨勪竴閮ㄥ垎(紜垏鍦拌錛屾槸MVC涓殑C錛夈傚簲鐢ㄧ▼搴忕殑琛屼負閫氬父琚畾涔変負鏈嶅姟鎺ュ彛錛岃屾帶鍒跺櫒浣垮緱鐢ㄦ埛鍙互璁塊棶搴旂敤鎵鎻愪緵鐨勬湇鍔°傛帶鍒跺櫒瑙f瀽鐢ㄦ埛杈撳叆錛屽茍灝嗗叾杞崲鎴愬悎鐞嗙殑妯″瀷鏁版嵁錛屼粠鑰屽彲浠ヨ繘涓姝ョ敱瑙嗗浘灞曠ず緇欑敤鎴楓係pring浠ヤ竴縐嶆娊璞$殑鏂瑰紡瀹炵幇浜嗘帶鍒跺櫒姒傚康錛岃繖鏍蜂嬌寰椾笉鍚岀被鍨嬬殑鎺у埗鍣ㄥ彲浠ヨ鍒涘緩銆係pring鏈韓鍖呭惈琛ㄥ崟鎺у埗鍣ㄣ佸懡浠ゆ帶鍒跺櫒銆佸悜瀵煎瀷鎺у埗鍣ㄧ瓑澶氱澶氭牱鐨勬帶鍒跺櫒銆?/p>
Spring鎺у埗鍣ㄦ灦鏋勭殑鍩虹鏄?code class="interfacename">org.springframework.mvc.Controller鎺ュ彛錛屽叾浠g爜濡備笅錛?/p>
public interface Controller { /** * Process the request and return a ModelAndView object which the DispatcherServlet * will render. */ ModelAndView handleRequest( HttpServletRequest request, HttpServletResponse response) throws Exception; }
浣犲彲浠ュ彂鐜?code class="interfacename">Controller鎺ュ彛浠呬粎澹版槑浜嗕竴涓柟娉曪紝瀹冭礋璐e鐞嗚姹傚茍榪斿洖鍚堥傜殑妯″瀷鍜岃鍥俱係pring MVC瀹炵幇鐨勫熀紜灝辨槸榪欎笁涓蹇碉細Mdel銆乂iew錛?code class="classname">ModelAndView錛変互鍙?Controller
銆傝櫧鐒?code class="interfacename">Controller鎺ュ彛鏄畬鍏ㄦ娊璞$殑錛屼絾Spring涔熸彁渚涗簡璁稿浣犲彲鑳戒細鐢ㄥ埌鐨勬帶鍒跺櫒銆侰ontroller鎺ュ彛浠呬粎瀹氫箟浜嗘瘡涓帶鍒跺櫒閮藉繀欏繪彁渚涚殑鍩烘湰鍔熻兘錛氬鐞嗚姹傚茍榪斿洖涓涓ā鍨嬪拰涓涓鍥俱?/p>
涓轟簡鎻愪緵涓濂楀熀紜璁炬柦錛屾墍鏈夌殑Spring鎺у埗鍣ㄩ兘緇ф壙浜?AbstractController
錛?code class="classname">AbstractController 鎻愪緵浜嗚濡傜紦瀛樻敮鎸佸拰mimetype璁劇疆榪欐牱鐨勫姛鑳姐?/p>
琛?3.3.聽AbstractController
鎻愪緵鐨勫姛鑳?/b>
鍔熻兘 | 鎻忚堪 |
---|---|
supportedMethods
|
鎸囧畾榪欎釜鎺у埗鍣ㄥ簲璇ユ帴鍙椾粈涔堟牱鐨勮姹傛柟娉曘傞氬父瀹冭璁劇疆鎴愬悓鏃舵敮鎸丟ET鍜孭OST錛屼絾鏄綘鍙互閫夋嫨浣犳兂鏀寔鐨勬柟娉曘傚鏋滄帶鍒跺櫒涓嶆敮鎸佽姹傚彂閫佺殑鏂規硶錛屽鎴風浼氬緱鍒伴氱煡錛堥氬父鏄姏鍑轟竴涓?code class="classname">ServletException錛夈? |
requiresSession
|
鎸囧畾榪欎釜鎺у埗鍣ㄦ槸鍚﹂渶瑕丠TTP session鎵嶈兘姝e父宸ヤ綔銆傚鏋滄帶鍒跺櫒鍦ㄦ病鏈塻ession鐨勬儏鍐典笅鎺ユ敹鍒拌姹傦紝瀹㈡埛绔細鍥犱負鎶涘嚭ServletException 鑰屽緱鍒伴氱煡銆? |
synchronizeSession
|
鎸囧畾controller鏄惁鍚屾鐢ㄦ埛鐨凥TTP session銆? |
cacheSeconds
|
鎸囧畾controller閫氱煡瀹㈡埛绔鏁版嵁鍐呭緙撳瓨鐨勭鏁幫紝涓鑸負澶т簬闆剁殑鏁存暟銆傞粯璁ゅ間負-1錛屽嵆涓嶇紦瀛樸? |
useExpiresHeader
|
鎸囧畾Controller鍦ㄥ搷搴旇姹傛椂鏄惁鍏煎HTTP 1.0 Expires header銆傜己鐪佸間負true 銆? |
useCacheHeader
|
鎸囧畾Controller鍦ㄧ浉搴旇姹傛椂鏄惁鍏煎HTTP 1.1 Cache-Control header銆傞粯璁ゅ間負true 銆? |
褰撲粠AbstractController
緇ф壙鏃訛紝闇瑕佸疄鐜?code class="literal">handleRequestInternal(HttpServletRequest, HttpServletResponse)鎶借薄鏂規硶錛岃鏂規硶灝嗙敤鏉ュ疄鐜拌嚜宸辯殑閫昏緫錛屽茍榪斿洖涓涓?code class="classname">ModelAndView瀵硅薄銆備笅闈㈣繖涓畝鍗曠殑渚嬪瓙婕旂ず浜嗗浣曚粠AbstractController
緇ф壙浠ュ強濡備綍鍦╝pplicationContext.xml涓繘琛岄厤緗?/p>
package samples; public class SampleController extends AbstractController { public ModelAndView handleRequestInternal( HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView mav = new ModelAndView("hello"); mav.addObject("message", "Hello World!"); return mav; } }
<bean id="sampleController" class="samples.SampleController"> <property name="cacheSeconds" value="120"/> </bean>
璇ontroller榪斿洖鐨凪odelAndView浣跨敤浜嗙‖緙栫爜鐨勮鍥懼悕錛堝敖綆¤繖鏍峰仛涓嶅ソ錛夛紝騫墮氱煡瀹㈡埛绔皢鍝嶅簲鏁版嵁緙撳瓨2鍒嗛挓銆傞櫎浜嗛氳繃浠ヤ笂鏂瑰紡鍒涘緩鍜岄厤緗甤ontroller涔嬪錛岃繕闇瑕侀厤緗甴andler mapping(璇峰弬鑰?a title="13.4.聽澶勭悊鍣ㄦ槧灝勶紙handler mapping錛? href="mk:@MSITStore:C:\Documents%20and%20Settings\ljl\妗岄潰\spring2.0-reference_final_zh_cn.chm::/ch13s04.html">絎?3.4聽鑺?鈥滃鐞嗗櫒鏄犲皠錛坔andler mapping錛夆?/a>)錛岃繖鏍瘋controller灝卞彲浠ュ伐浣滀簡銆?/p>
灝界鍙互緇ф壙AbstractController
鏉ュ疄鐜拌嚜宸辯殑鎺у埗鍣紝涓嶈繃Spring鎻愪緵鐨勪紬澶氭帶鍒跺櫒鍑忚交浜嗘垜浠紑鍙戠畝鍗昅VC搴旂敤鏃剁殑璐熸媴銆?code class="classname">ParameterizableViewController鍩烘湰涓婂拰涓婇潰渚嬪瓙涓殑涓鏍鳳紝涓嶅悓鐨勬槸錛屼綘鍙互鍦╝pplicationContext.xml閰嶇疆涓寚瀹氳繑鍥炶鍥懼悕浠庤岄伩鍏嶄簡鍦↗ava浠g爜涓殑紜紪鐮併?/p>
UrlFilenameViewController
浼氭鏌RL錛岃幏鍙栨枃浠惰姹傜殑鏂囦歡鍚嶏紝騫舵妸瀹冧綔涓鴻鍥懼悕鍔犱互浣跨敤銆傘備緥濡傦紝http://www.springframework.org/index.html
瀵瑰簲鐨勮鍥炬枃浠跺悕鏄?code class="literal">index銆?/p>
MultiActionController
灝嗗涓涓?action)鍚堝茍鍦ㄤ竴涓帶鍒跺櫒閲岋紝榪欐牱鍙互鎶婄浉鍏沖姛鑳界粍鍚堝湪涓璧楓?code class="classname">MultiActionController浣嶄簬org.springframework.web.mvc.multiaction
鍖呬腑錛屽畠閫氳繃灝嗚姹傛槧灝勫埌姝g‘鐨勬柟娉曞悕鏉ヨ皟鐢ㄦ柟娉曘傚綋鍦ㄤ竴涓帶鍒跺櫒瀛樺湪澶ч噺鍏叡鐨勮涓猴紝浣嗘槸鏈夊涓皟鐢ㄥ叆鍙f椂錛屼嬌鐢?code class="classname">MultiActionController灝辯壒鍒柟渚褲?/p>
琛?3.4.聽MultiActionController
鎻愪緵鐨勫姛鑳?/b>
鍔熻兘 | 鎻忚堪 |
---|---|
delegate
|
MultiActionController 鏈変袱縐嶄嬌鐢ㄦ柟寮忋傜涓縐嶆槸浣犵戶鎵?code class="classname">MultiActionController錛屽茍鍦ㄥ瓙綾諱腑鎸囧畾鐢?code class="interfacename">MethodNameResolver瑙f瀽鐨勬柟娉曪紙榪欑鎯呭喌涓嬩笉闇瑕佽繖涓猟elegate鍙傛暟錛夈傜浜岀鏄綘瀹氫箟涓涓唬鐞嗗璞★紝鐢卞畠鎻愪緵MethodNameResolver 瑙f瀽鍑烘潵鐨勬柟娉曪紙榪欑鎯呭喌涓嬶紝浣犲繀欏諱嬌鐢ㄨ繖涓厤緗弬鏁板畾涔変唬鐞嗗璞★級銆? |
methodNameResolver
|
MultiActionController 闇瑕佷竴縐嶇瓥鐣ワ紝浣垮叾鍙互閫氳繃瑙f瀽璇鋒眰淇℃伅鏉ヨ幏寰楄璋冪敤鐨勬柟娉曘傝繖涓В鏋愮瓥鐣ョ敱MethodNameResolver 榪欎釜鎺ュ彛瀹氫箟鐨勩傝繖涓弬鏁板厑璁鎬綘瀹炵幇MethodNameResolver 鎺ュ彛錛岀劧鍚庡湪鎺у埗鍣ㄤ腑浣跨敤浣犵殑絳栫暐銆? |
MultiActionController
鎵鏀寔鐨勬柟娉曢渶瑕佺鍚堜笅鍒楁牸寮忥細
// anyMeaningfulName can be replaced by any methodname
public [ModelAndView | Map | void] anyMeaningfulName(HttpServletRequest, HttpServletResponse [, Exception | AnyObject]);
娉ㄦ剰錛氬湪姝?span class="emphasis">涓嶅厑璁?/em>鏂規硶閲嶈澆錛屽洜涓?code class="classname">MultiActionController鏃犳硶鍒嗚鯨鍑洪噸杞斤紙overloading錛変簡鐨勬柟娉曘傛澶栵紝浣犲彲浠ュ畾涔?span class="emphasis">exception handler鏉ュ鐞嗘柟娉曚腑鎶涘嚭鐨勫紓甯搞?
Exception
鍙傛暟鏄彲閫夌殑錛屽畠鍙互鏄?span class="emphasis">浠諱綍寮傚父錛屽彧瑕佸畠鏄?code class="classname">java.lang.Exception鎴?code class="classname">java.lang.RuntimeException鐨勫瓙綾匯?code class="classname">AnyObject鍙傛暟涔熸槸鍙夌殑錛屽畠鍙互鏄?span class="emphasis">浠諱綍瀵硅薄銆侶TTP Request涓殑鍙傛暟浼氬瓨鍦ㄨ繖涓璞′腑錛屼互渚夸嬌鐢ㄣ?/p>
涓嬮潰鍑犱釜渚嬪瓙紺鴻寖浜?code class="classname">MultiActionController姝g‘鐨勬柟娉曞畾涔夈?/p>
鏍囧噯鏍煎紡(璺?code class="interfacename">Controller鎺ュ彛瀹氫箟鐨勪竴鏍?銆?/p>
public ModelAndView doRequest(HttpServletRequest, HttpServletResponse)
涓嬮潰榪欎釜鏂規硶鏀寔Login
鍙傛暟錛?榪欎釜鍙傛暟涓寘鍚粠璇鋒眰涓娊鍙栧嚭鏉ョ殑淇℃伅銆?/p>
public ModelAndView doLogin(HttpServletRequest, HttpServletResponse, Login)
涓嬮潰榪欎釜鏂規硶鍙互澶勭悊Exception
銆?/p>
public ModelAndView processException(HttpServletRequest, HttpServletResponse, IllegalArgumentException)
涓嬮潰榪欎釜鏂規硶涓嶈繑鍥炰換浣曟暟鍊箋?(璇峰弬鑰冨悗闈㈢殑绔犺妭 絎?3.11聽鑺?鈥滄儻渚嬩紭鍏堝師鍒?convention over configuration)鈥?/a>)
public void goHome(HttpServletRequest, HttpServletResponse)
This signature has a Map
return type (see the section entitled 絎?3.11聽鑺?鈥滄儻渚嬩紭鍏堝師鍒?convention over configuration)鈥?/a> below).
涓嬮潰榪欎釜鏂規硶榪斿洖涓涓?code class="interfacename">Map銆?(璇峰弬鑰冨悗闈㈢殑绔犺妭絎?3.11聽鑺?鈥滄儻渚嬩紭鍏堝師鍒?convention over configuration)鈥?/a>)
public Map doRequest(HttpServletRequest, HttpServletResponse)
MethodNameResolver
璐熻矗浠庤姹備腑瑙f瀽鍑洪渶瑕佽皟鐢ㄧ殑鏂規硶鍚嶇О銆備笅闈㈡槸Spring涓唴緗殑涓変釜MethodNameResolver
瀹炵幇銆?/p>
ParameterMethodNameResolver
- 瑙f瀽璇鋒眰鍙傛暟錛屽茍灝嗗畠浣滀負鏂規硶鍚嶃?瀵瑰簲http://www.sf.net/index.view?testParam=testIt
鐨勮姹傦紝浼氳皟鐢?testIt(HttpServletRequest,HttpServletResponse)
鏂規硶)銆備嬌鐢?code class="literal">paramName閰嶇疆鍙傛暟錛屽彲浠ヨ瀹氳媯鏌ョ殑鍙傛暟銆?/p>
InternalPathMethodNameResolver
-浠庤礬寰勪腑鑾峰彇鏂囦歡鍚嶄綔涓烘柟娉曞悕 (http://www.sf.net/testing.view
鐨勮姹備細璋冪敤testing(HttpServletRequest,HttpServletResponse)
鏂規硶銆?/p>
PropertiesMethodNameResolver
- 浣跨敤鐢ㄦ埛鑷畾涔夌殑灞炴у璞★紝灝嗚姹傜殑URL鏄犲皠鍒版柟娉曞悕銆傚綋灞炴т腑鍖呭惈/index/welcome.html=doIt
鏃訛紝鍙戝埌/index/welcome.html
鐨勮姹備細璋冪敤doIt(HttpServletRequest, HttpServletResponse)
榪欎釜鏂規硶銆?榪欎釜鏂規硶鍚嶈В鏋愬櫒鍙互鍜?code class="literal">PathMatcher涓璧峰伐浣滐紝姣斿涓婅竟閭d釜URL鍐欐垚/**/welcom?.html
涔熸槸鍙互鐨勩?/p>
鎴戜滑鏉ョ湅涓緇勪緥瀛愩傞鍏堟槸涓涓嬌鐢?code class="classname">ParameterMethodNameResolver鍜屼唬鐞嗭紙delegate錛夊睘鎬х殑渚嬪瓙錛屽畠鎺ュ彈鍖呭惈鍙傛暟鍚?method"鐨勮姹傦紝璋冪敤鏂規硶retrieveIndex
錛?
<bean id="paramResolver" class="org....mvc.multiaction.ParameterMethodNameResolver">
<property name="paramName" value="method"/>
</bean>
<bean id="paramMultiController" class="org....mvc.multiaction.MultiActionController">
<property name="methodNameResolver" ref="paramResolver"/>
<property name="delegate" ref="sampleDelegate"/>
</bean>
<bean id="sampleDelegate" class="samples.SampleDelegate"/>
## together with
public class SampleDelegate {
public ModelAndView retrieveIndex(HttpServletRequest req, HttpServletResponse resp) {
return new ModelAndView("index", "date", new Long(System.currentTimeMillis()));
}
}
褰撲嬌鐢ㄤ笂闈㈢殑浠g悊瀵硅薄鏃訛紝鎴戜滑涔熷彲浠ヤ嬌鐢?code class="classname">PropertiesMethodNameRseolver鏉ュ尮閰嶄竴緇刄RL錛屽皢瀹冧滑鏄犲皠鍒版垜浠畾涔夌殑鏂規硶涓婏細
<bean id="propsResolver" class="org....mvc.multiaction.PropertiesMethodNameResolver"> <property name="mappings"> <value> /index/welcome.html=retrieveIndex /**/notwelcome.html=retrieveIndex /*/user?.html=retrieveIndex </value> </property> </bean> <bean id="paramMultiController" class="org....mvc.multiaction.MultiActionController"> <property name="methodNameResolver" ref="propsResolver"/> <property name="delegate" ref="sampleDelegate"/> </bean>
Spring鐨?span class="emphasis">CommandController鏄疭pring MVC鐨勯噸瑕侀儴鍒嗐傚懡浠ゆ帶鍒跺櫒鎻愪緵浜嗕竴縐嶅拰鏁版嵁瀵硅薄浜や簰鐨勬柟寮忥紝騫跺姩鎬佸湴灝嗘潵鑷?code class="interfacename">HttpServletRequest鐨勫弬鏁扮粦瀹氬埌浣犳寚瀹氱殑鏁版嵁瀵硅薄涓娿傚畠鐨勫姛鑳藉拰Struts涓殑ActionForm
鏈夌偣鍍忥紝涓嶈繃鍦⊿pring涓紝浣犱笉闇瑕佸疄鐜頒換浣曟帴鍙f潵瀹炵幇鏁版嵁緇戝畾銆傞鍏堬紝璁╂垜浠湅涓涓嬫湁鍝簺鍙互浣跨敤鐨勫懡浠ゆ帶鍒跺櫒錛?/p>
AbstractCommandController
錛嶏紞浣犲彲浠ヤ嬌鐢ㄨ鎶借薄鍛戒護鎺у埗鍣ㄦ潵鍒涘緩鑷繁鐨勫懡浠ゆ帶鍒跺櫒錛屽畠鑳藉灝嗚姹傚弬鏁扮粦瀹氬埌浣犳寚瀹氱殑鍛戒護瀵硅薄銆傝繖涓被騫朵笉鎻愪緵浠諱綍琛ㄥ崟鍔熻兘錛屼絾鏄畠鎻愪緵楠岃瘉鍔熻兘錛屽茍涓旇浣犲湪瀛愮被涓幓瀹炵幇濡備綍澶勭悊鐢辮姹傚弬鏁頒駭鐢熺殑鍛戒護瀵硅薄銆?
AbstractFormController
錛嶏紞涓涓敮鎸佽〃鍗曟彁浜ょ殑鎶借薄鎺у埗鍣ㄧ被銆備嬌鐢ㄨ繖涓帶鍒跺櫒錛屼綘鍙互瀹氫箟琛ㄥ崟錛屽茍浣跨敤浠庢帶鍒跺櫒鑾峰彇鐨勬暟鎹璞℃瀯寤鴻〃鍗曘傚綋鐢ㄦ埛杈撳叆琛ㄥ崟鍐呭錛?code class="classname">AbstractFormController灝嗙敤鎴瘋緭鍏ョ殑鍐呭緇戝畾鍒板懡浠ゅ璞★紝楠岃瘉琛ㄥ崟鍐呭錛屽茍灝嗚瀵硅薄浜ょ粰鎺у埗鍣紝瀹屾垚鐩稿簲鐨勬搷浣溿傚畠鏀寔鐨勫姛鑳芥湁闃叉閲嶅鎻愪氦銆佽〃鍗曢獙璇佷互鍙婁竴鑸殑琛ㄥ崟澶勭悊嫻佺▼銆傚瓙綾婚渶瑕佸疄鐜拌嚜宸辯殑鏂規硶鏉ユ寚瀹氶噰鐢ㄥ摢涓鍥炬潵鏄劇ず杈撳叆琛ㄥ崟錛屽摢涓鍥炬樉紺鴻〃鍗曟紜彁浜ゅ悗鐨勭粨鏋溿傚鏋滀綘闇瑕佽〃鍗曪紝浣嗕笉鎯沖湪搴旂敤涓婁笅鏂囦腑鎸囧畾鏄劇ず緇欑敤鎴風殑瑙嗗浘錛屽氨浣跨敤榪欎釜鎺у埗鍣ㄣ?
SimpleFormController
錛嶏紞榪欐槸涓涓猣orm cotnroller錛屽綋闇瑕佹牴鎹懡浠ゅ璞℃潵鍒涘緩鐩稿簲鐨刦orm鐨勬椂鍊欙紝璇ョ被鍙互鎻愪緵鏇村鐨勬敮鎸併備綘鍙互涓哄叾鎸囧畾涓涓懡浠ゅ璞★紝鏄劇ず琛ㄥ崟鐨勮鍥懼悕錛屽綋琛ㄥ崟鎻愪氦鎴愬姛鍚庢樉紺虹粰鐢ㄦ埛鐨勮鍥懼悕絳夌瓑銆?
AbstractWizardFormController
錛嶏紞榪欐槸涓涓娊璞$被錛岀戶鎵胯繖涓被闇瑕佸疄鐜?code class="literal">validatePage()銆?code class="literal">processFinish() 鍜?code class="literal">processCancel() 鏂規硶銆?/p>
浣犳湁鍙兘涔熼渶瑕佸啓涓涓瀯閫犲櫒錛屽畠鑷沖皯闇瑕佽皟鐢?code class="literal">setPages()鍜?code class="literal">setCommandName()鏂規硶銆俿etPages()鐨勫弬鏁版槸涓涓猄tring鏁扮粍錛岃繖涓暟緇勫寘鍚簡緇勬垚鍚戝鐨勮鍥懼悕銆俿etCommandName()鐨勫弬鏁版槸涓涓猄tring錛岃鍙傛暟灝嗙敤鏉ュ湪瑙嗗浘涓皟鐢ㄤ綘鐨勫懡浠ゅ璞°?/p>
鍜?code class="classname">AbstractFormController鐨勫疄鐜頒竴鏍? 浣犻渶瑕佷嬌鐢ㄥ懡浠ゅ璞★紙鍏跺疄灝辨槸涓涓狫avaBean錛?榪欎釜bean涓寘鍚簡琛ㄥ崟鐨勪俊鎭級銆備綘鏈変袱涓夋嫨錛氬湪鏋勯犲嚱鏁頒腑璋冪敤setCommandClass()
鏂規硶錛堝弬鏁版槸鍛戒護瀵硅薄鐨勭被鍚嶏級錛屾垨鑰呭疄鐜?code class="literal">formBackingObject()鏂規硶銆?/p>
AbstractWizardFormController
鏈夊嚑涓綘鍙互澶嶅啓錛坥verride錛夌殑鏂規硶銆傛渶鏈夌敤鐨勪竴涓槸referenceData(..)
銆傝繖涓柟娉曞厑璁鎬綘鎶婃ā鍨嬫暟鎹互Map
鐨勬牸寮忎紶閫掔粰瑙嗗浘錛?code class="literal">getTargetPage() 鍏佽浣犲姩鎬佸湴鏇存敼鍚戝鐨勯〉闈㈤『搴忥紝鎴栬呯洿鎺ヨ煩榪囨煇浜涢〉闈紱onBindAndValidate()
鍏佽浣犲鍐欏唴緗殑緇戝畾鍜岄獙璇佹祦紼嬨?/p>
鏈鍚庯紝鎴戜滑鏈夊繀瑕佹彁涓涓?code class="literal">setAllowDirtyBack() 鍜?code class="literal">setAllowDirtyForward()涓や釜鏂規硶銆?浣犲彲浠ュ湪getTargetPage()
涓皟鐢ㄨ繖涓や釜鏂規硶錛岃繖涓や釜鏂規硶灝嗗喅瀹氬湪褰撳墠欏甸潰楠岃瘉澶辮觸鏃訛紝鏄惁鍏佽鍚戝鍓嶇Щ鎴栧悗閫銆?/p>
AbstractWizardFormController
鐨勬洿璇︾粏鍐呭璇峰弬鑰僇avaDoc銆傚湪Spring闄勫甫鐨勪緥瀛恓PetStore涓紝鏈変竴涓叧浜庡悜瀵煎疄鐜扮殑渚嬪瓙錛?org.springframework.samples.jpetstore.web.spring.OrderFormController
銆?/p>
灝辮薄鍜孲pring闆嗘垚鐨勫叾浠栬〃鐜板眰鎶鏈竴鏍鳳紝瀵逛簬JSP欏甸潰浣犻渶瑕佷竴涓鍥捐В鏋愬櫒鏉ヨВ鏋愩傛渶甯哥敤鐨凧SP瑙嗗浘瑙f瀽鍣ㄦ槸InternalResourceViewResolver鍜?tt class="literal">ResourceBundleViewResolver銆傚畠浠瀹氫箟鍦╓ebApplicationContext閲岋細
# The ResourceBundleViewResolver: <bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver"> <property name="basename"><value>views</value></property> </bean> # And a sample properties file is uses (views.properties in WEB-INF/classes): welcome.class=org.springframework.web.servlet.view.JstlView welcome.url=/WEB-INF/jsp/welcome.jsp productList.class=org.springframework.web.servlet.view.JstlView productList.url=/WEB-INF/jsp/productlist.jsp
浣犲彲浠ョ湅鍒癛esourceBundleViewResolver闇瑕佷竴涓睘鎬ф枃浠舵潵鎶婅鍥懼悕縐版槧灝勫埌 1)綾誨拰 2) URL銆?閫氳繃ResolverBundleViewResolver錛屼綘鍙互鐢ㄤ竴涓В鏋愬櫒鏉ヨВ鏋愪袱縐嶇被鍨嬬殑瑙嗗浘銆?/p>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property> <property name="prefix"><value>/WEB-INF/jsp/</value></property> <property name="suffix"><value>.jsp</value></property> </bean>
InternalResourceBundleViewResolver鍙互閰嶇疆鎴愪嬌鐢↗SP欏甸潰銆備綔涓哄ソ鐨勫疄鐜版柟寮忥紝寮虹儓鎺ㄨ崘浣犲皢JSP鏂囦歡鏀懼湪WEB-INF涓嬬殑涓涓洰褰曚腑錛岃繖鏍峰鎴風灝變笉浼氱洿鎺ヨ闂埌瀹冧滑銆?/p>
Spring 2.0鐗堟湰鏀寔鎵╁睍XML閰嶇疆錛岀潃瀹炲叴濂嬩簡涓涓嬶紝鍦ㄦ垜鐪嬫潵錛孲pring浣滀負鐩墠鏈嫻佽鐨勬鏋訛紝涓嶈兘鎵╁睍鐢ㄦ埛鑷畾涔夌殑閰嶇疆錛屽疄鍦ㄦ槸Spring鐨勪竴涓緢涓嶇埥鐨勫湴鏂癸紝<bean />鐨勬柟寮忕敤璧鋒潵姣旇緝閫氱敤錛岃搗鐮佸埌鐩墠涓烘絎﹀悎澶ч儴鍒嗕漢鐨勪嬌鐢ㄤ範鎯紝騫朵笖鑳藉畬鎴怱pring鎵鏈夌殑閰嶇疆鎿嶄綔,浣嗘槸瀵逛簬絎笁鏂圭殑鎻愪緵鍟嗘垨鍒欎細緇忓父鎵╁睍Spring鍔熻兘鐨勫紑鍙戣呮潵璇?浣跨敤<bean />榪欐牱鐨勯厤緗柟寮忔垨璁鎬笉鏄粬浠渶鎯寵鐨勶紝浠栦滑闇瑕佷嬌緇勪歡鐨勯厤緗洿鍔犵洿瑙傘佹槗闃呰銆佹槗鎵╁睍鈥︹﹁瘯鎯充嬌鐢ㄤ笅闈㈢殑閰嶇疆鏂瑰紡 浠g爜
涓婇潰鐨勪唬鐮佷腑閰嶇疆浜嗕袱涓粍浠訛紝datasource鍜宑ache緇勪歡錛岀浉姣旀櫘閫氱殑bean&propertiy鏂瑰紡,寰堟樉鐒訛紝榪欑閰嶇疆鏂瑰紡鏇寸洿瑙傦紝鏇存槗璇伙紝鏇撮噸瑕佺殑鏄紝濡傛灉浣滀負緇勪歡鍙戝竷錛屼嬌鐢ㄨ呬篃鍙互寰堟柟渚垮揩鎹風殑寮濮嬩嬌鐢紝鑰屼笉闇瑕佸叧蹇冪粍浠剁殑浠諱綍瀹炵幇緇嗚妭銆? 鎵╁睍XML閰嶇疆澶ц嚧闇瑕佷竴涓嬪嚑涓楠? 鎻愪緵涓涓畝鍗曠殑渚嬪瓙錛屾潵璇存槑濡備綍鍘繪墿灞曚竴涓猄pring閰嶇疆錛岄渶姹傚涓嬶細浣跨敤鑷畾涔夋爣絳懼畾涔変竴涓畝鍗曠殑bean錛岃繖涓猙ean鏈変竴涓垨澶氫釜灞炴э紝鏍囩瀹氫箟瀹屾垚鍚庯紝鍙互鍦ㄥ叾浠栭」鐩腑鐢ㄨ嚜瀹氫箟鏍囩鏉ュ畾涔夎bean銆?/p> 棣栧厛錛屽垱寤轟竴涓渶瑕佹墿灞曠殑緇勪歡錛屽湪榪欓噷鍙槸涓涓畝鍗曠殑bean錛岃屼笖榪欎釜bean鍙湁涓涓睘鎬ge. 浠g爜
鐒跺悗錛屽緩绔嬩竴涓獂sd鏂囦歡錛屾潵鎻忚堪榪欎釜bean 浠g爜
鍦ㄤ笂闈㈢殑xsd鏂囦歡鎻忚堪浜嗕竴涓柊鐨則argetNamespace錛屽茍鍦ㄨ繖涓┖闂翠腑瀹氫箟浜嗕竴涓猲ame涓簅ne鐨別lement,one鏈変竴涓猘ge灞炴э紝綾誨瀷涓簊tring錛岄粯璁ゅ間負99999.xsd鏂囦歡鏄痻ml DTD鐨勬浛浠h咃紝浣跨敤XML Schema璇█榪涜緙栧啓錛岃繖閲屽xsd schema涓嶅仛澶瑙i噴錛屾湁鍏磋叮鍙互鍙傝冪浉鍏崇殑璧勬枡銆? 鍒涘緩涓涓狫ava鏂囦歡錛岃鏂囦歡瀹炵幇浜咮eanDefinitionParser鎺ュ彛錛岀敤鏉ヨВ鏋恱sd鏂囦歡涓殑瀹氫箟騫舵敞鍐屽埌緇勪歡涓? 浠g爜
涓婇潰鐨勪唬鐮佷粎浠呭疄鐜頒簡涓涓柟娉昿ublic BeanDefinition parse(Element arg0, ParserContext arg1)錛岃緗浉鍏崇殑Bean Class錛岃В鏋愪簡瀵瑰簲鐨剎sd鏂囦歡錛屽茍灝嗚В鏋愮殑鍐呭娉ㄥ唽鍒頒笂涓嬫枃涓紝鍚屾椂榪斿洖涓涓狟eanDefinition瀵硅薄錛圔eanDefinition鏄疭pring鐨刡ean瀹氫箟錛屾彁渚涗簡bean閮ㄥ垎鐨勬搷浣滄柟娉曪紝濡俰sSingleton()銆乮sLazyInit()絳?銆? 娉ㄦ剰錛宨d灞炴ф槸涓涓粯璁ょ殑灞炴э紝鍙互涓嶅湪xsd鏂囦歡涓弿榪幫紝浣嗘槸闇瑕佹敞鍐屽畠錛屽惁鍒欏皢鏃犳硶閫氳繃getBean鏂規硶鑾峰彇鏍囩瀹氫箟鐨刡ean錛屼篃鏃犳硶琚叾浠朾ean寮曠敤銆? 浠g爜
鐒跺悗涓虹粍浠剁紪鍐欎竴涓狧andler鏂囦歡錛屾墿灞曡嚜NamespaceHandlerSupport錛屽畠鐨勪綔鐢ㄦ槸灝嗙粍浠舵敞鍐屽埌Spring瀹瑰櫒 浠g爜
瀹為檯鎵ц鐨勮繃紼嬪彧鏈変竴鍙ヤ唬鐮侊紝娉ㄥ唽浜嗕竴涓悕瀛椾負one鐨勬墿灞曢厤緗紝鍖呭惈浜哅yBeanDefinitionParser鎵parser鐩稿叧xsd鐨勫唴瀹廣? 鍒頒簡榪欓噷錛屼竴涓猄pring鎵╁睍鏍囩宸茬粡瀹屾垚錛屼絾鏄垜浠洰鍓嶈繕娌″姙娉曚嬌鐢ㄥ畠錛孲pring娌¢偅涔堣仾鏄庯紝瀹冩棤娉曠煡閬撴垜浠湪浠涔堝湴鏂瑰畾涔変簡鍝簺鎵╁睍鏍囩錛岃繖浜涙爣絳懼皢琚皝瑙f瀽錛岃繖涓繃紼嬭鎴戜滑閫氳繃涓浜涙枃浠舵潵鍛婄煡Spring鐭ラ亾錛屽畠浠氨鏄痵pring.handlers鍜宻pring.schemas錛屽畠浠斁鍦∕ETA-INF鐩綍涓紝Spring.jar鐨凪ETA-INF鐩綍涓篃鏈夊悓鍚嶇殑鏂囦歡錛屽畠浠殑鏂囦歡鍐呭鍩烘湰涓婃槸鐩鎬技鐨勶紝鑰孲pring鍦ㄦ墽琛岃繃紼嬩腑錛屽鏋滃彂鐜板叾浠杍ar鏂囦歡鐨凪ETA-INF鏂囦歡澶逛腑鍖呭惈鏈夎繖涓や釜鏂囦歡錛孲pring灝嗕細鍚堝茍瀹冧滑銆? 浠g爜
spring.handlers 浠g爜
spring.schemas灝嗗憡璇塖pring閰嶇疆鏂囦歡鐭ラ亾錛屽鏋滃湪閰嶇疆涓紩鐢╤ttp://www.mysite.org/schema/mytag.xsd錛屽畠搴旇鍘諱粈涔堝湴鏂規壘鐩稿簲鐨剎sd鏂囦歡銆? 鐜板湪涓烘錛屼竴涓畬鏁寸殑xml鎵╁睍鏍囩鍏ㄩ儴瀹屾垚錛屽仛涓涓皬搴旂敤嫻嬭瘯涓涓嬨? 浠g爜
鍦▁ml鏂囦歡寮曠敤涓婂彲浠ョ湅鍒?閰嶇疆浜嗕竴涓悕瀛椾負tag鐨勫悕縐扮┖闂?鐩爣涓篽ttp://www.mysite.org/schema/mytag鍛藉悕絀洪棿,榪欎釜鐩爣鍚嶇О絀洪棿蹇呴』鏄瓨鍦ㄤ簬欏圭洰鐨勫紩鐢ㄤ腑鐨?mytag.xsd涓墍瀹氫箟鐨?. 浠g爜
涓婇潰瀹氫箟浜嗕竴涓猧d涓簅neBean鐨勭粍浠訛紝浣跨敤浜嗏渙ne鈥濇墿灞曟爣絳撅紝涔熷氨鏄垜浠湪handler涓墍娉ㄥ唽鐨勶紝緇勪歡age灞炴х殑鍊間負99銆? Main.java 浠g爜
榪愯嫻嬭瘯紼嬪簭錛岀粨鏋滃涓? 浠g爜
Spring鐨剎ml鎵╁睍鏄竴涓潪甯告湁鐢ㄧ殑鐗規э紝鍦⊿pring2.0鐨勭増鏈腑涔熸彁渚涗簡涓浜涙柊鐨勬爣絳句嬌鐢紝濡?lt;aop>,<tx>絳?浣嗗氨鐩墠鏉ヨ鍙楀ぇ瀹跺叧娉ㄧ▼搴﹀茍涓嶉珮錛屾垜鎯沖ぇ閮ㄥ垎浣跨敤Spring鐨勫紑鍙戜漢鍛橀兘鍦ㄤ嬌鐢⊿pring寮鍙戜紒涓氬簲鐢紝鑰孲pring鎵鎻愪緵鐨?lt;bean />瀹氫箟鐨勬柟寮忓浜庡紑鍙戜漢鍛樻潵璇村凡緇忚兘澶熸弧瓚抽渶瑕侊紝浣嗘槸濡傛灉鐪嬬殑鏇磋繙涓浜涳紝鍦⊿pring浠ュ悗鐨勫彂灞曡繃紼嬩腑錛寈ml鎵╁睍搴旇浼氭垚涓簊pring鐨勬牳蹇冪壒鎬т箣涓錛屾垨璁稿埌鏃跺ぇ瀹朵細涔犳儻榪欐牱鐨勬柟寮忔潵緙栧啓Spring閰嶇疆鏂囦歡鍚? 浠g爜
|
璇勮 聽聽聽鍏?2 鏉? | 鍙戣〃璇勮 |
浠g爜
瀵逛簬綆鍗曠殑搴旂敤鍙互鐢╬鏍囩灝卞ソ浜嗐? |
璇鋒眰鐨勫垎鍙?/p> 璇鋒眰棣栧厛鍒拌揪DispatcherServlet錛屽簲鐢ㄦ湇鍔″櫒浼氭牴鎹甒eb搴旂敤涓瓀eb.xml鏂囦歡瀹氫箟鐨剈rl鏄犲皠灝嗙浉搴旂殑璇鋒眰鍒嗗彂鍒癉ispatcherServlet涓?/p> 璇鋒眰鐨勫鐞?/p> DispatcherServlet浼氭煡鎵劇浉搴旂殑HandlerMapping鎺ュ彛鐨勫疄鐜扮被錛岃皟鐢ㄥ叾涓殑鏂規硶錛欻andlerExecutionChain getHandler(HttpServletRequest request) throws Exception錛岃鏂規硶浼氳繑鍥炰竴涓狧andlerExecutionChain銆傝繑鍥炵殑HandlerExecutionChain涓寘鍚簡闆朵釜鎴栬呮槸澶氫釜Interceptor鍜屼竴涓鐞嗚姹傜殑Handler銆侱ispatcherServlet浼氳皟鐢↖nterceptor涓殑preHandle() 鏂規硶銆傜劧鍚庡鐞咹andler錛岃繖涓狧andler鐩稿綋浜嶴truts涓瑼ction錛屽湪SpringMVC涓粯璁ょ殑瀹炵幇鏄疌ontroller鎺ュ彛錛屾槸鍏蜂綋澶勭悊璇鋒眰鐨勪唬鐮佹墍椹葷暀鐨勫湴鏂廣備簨瀹炰笂HandlerExecutionChain涓殑getHandler()榪斿洖鐨勬槸涓涓狾bject綾誨瀷銆侱ispatcherServlet涓嶄細鐩存帴璋冪敤getHandler錛堬級榪斿洖瀵硅薄涓殑鏂規硶錛孌ispatcherServlet浼氭煡鎵劇浉搴旂殑HandlerAdapter錛岀劧鍚庡叿浣撻氳繃HandlerAdapter鏉ヨ皟鐢╣etHandler()榪斿洖鐨刪andler瀵硅薄涓殑鏂規硶銆傚氨鏄鎴戜滑鍙互瀹炵幇鑷繁鐨凥andlerAdapter鐒跺悗閫氳繃IoC娉ㄥ叆鍒癉ispatcherServlet涓紝浠庤屽彲浠ュ疄鐜頒竴濂楄嚜瀹氫箟鐨勬帶鍒跺櫒銆傞殢鍚嶥ispatcherServlet浼氳皟鐢↖nterceptor涓殑postHandle()鏂規硶銆? 瑙嗗浘鐨勫鐞?/p> DispatcherServlet浼氭湡鏈汬ander榪斿洖涓涓狹odelAndView錛孌ispatcherServlet浼氭牴鎹墍榪斿洖鐨凪odelAndView瀵硅薄鎵鍖呭惈鐨勪俊鎭繘琛岃鍥劇殑娓叉煋銆傝搗鍏蜂綋鍑烘潵嫻佺▼濡備笅錛?/p> 棣栧厛DispatcherServlet浼氭牴鎹甃ocaleResolver鏉ヨ瘑鍒姹備腑鐨凩ocale錛屽紑鍙戜漢鍛樺彲浠ヨ嚜宸卞疄鐜癓ocaleResolver鎺ュ彛錛岀劧鍚庨氳繃IoC娉ㄥ叆鍒癉ispatcherServlet涓紝鐒跺悗DispatcherServlet浼氬垽鏂璏odelAndView涓槸鍚﹀凡緇忓寘鍚簡鎺ュ彛View鐨勫叿浣撳疄鐜幫紝濡傛灉鍖呭惈浜嗭紝鍒欑洿鎺ヨ皟鐢╒iew涓殑鏂規硶render(Map model, HttpServletRequest request, HttpServletResponse response)銆傚鏋滀笉鍖呭惈錛屽垯璇存槑璇odelAndView鍙槸鍖呭惈浜哣iew鐨勫悕縐板紩鐢紝DispatcherServlet浼氳皟鐢╒iewResolver涓殑resolveViewName(String viewName, Locale locale)鏉ヨВ鏋愬叾鐪熸鐨勮鍥俱傝鏂規硶浼氳繑鍥炰竴涓猇iew鐨勫叿浣撳疄鐜般?/p> 瑙嗗浘鐨勬覆鏌?/p> Spring鏀寔澶氱瑙嗗浘鎶鏈紝鍏朵腑姣旇緝甯哥敤鐨勫寘鎷湁Jstl瑙嗗浘錛孷eloctiy瑙嗗浘錛孎reeMarker瑙嗗浘絳夈傚Jstl瑙嗗浘鐨勬覆鏌揝pring鏄氳繃JstlView榪欎釜綾誨叿浣撳疄鐜扮殑銆備簨瀹炰笂鍏舵渶緇堢殑娓叉煋鏄氦緇欏鍣ㄦ潵鍋氱殑錛孲pring鍙槸閫氳繃RequestDispatcher瀹炵幇浜嗘湇鍔″櫒鍐呴儴璇鋒眰鐨凢orward銆傝屽浜庢ā鏉胯鍥撅紝濡俈eloctiy鍜孎reeMarker絳夛紝Spring浼氬垵濮嬪寲鍏剁浉搴旂殑妯℃澘寮曟搸錛岀敱妯℃澘寮曟搸鐢熸垚鏈緇堢殑Html欏甸潰鐒跺悗鍦ㄥ悎騫跺埌Response鐨勮緭鍑烘祦涓?/p> 寮傚父鐨勫鐞?/p> 濡傛灉鍦℉ander涓鐞嗚姹傛槸鎶涘嚭寮傚父錛孌ispatcherServlet浼氭煡鎵綡andlerExceptionResolver鎺ュ彛鐨勫叿浣撳疄鐜幫紝璇ユ帴鍙e畾涔変簡涓涓柟娉曪細 ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)錛屽疄鐜扮被闇瑕佸疄鐜拌鏂規硶浠ヤ究瀵瑰紓甯歌繘琛屽鐞嗭紝鏈鍚庤鏂規硶闇瑕佽繑鍥炰竴涓狹odelAndView銆?/p> SpringMVC鐨勪竴浜涙葷粨 |
public abstract class HttpServletBean
Simple extension of HttpServlet
which treats its config parameters (init-param
entries within the servlet
tag in web.xml
) as bean properties.
HttpServlet鐨勭畝鍗曟墿灞曠敤鏉ュ鐞?錛坕nit-param錛塱n the web.xml
A handy superclass for any type of servlet. Type conversion of config parameters is automatic, with the corresponding setter method getting invoked with the converted value. It is also possible for subclasses to specify required properties. Parameters without matching bean property setter will simply be ignored.
This servlet leaves request handling to subclasses, inheriting the default behavior of HttpServlet (doGet
, doPost
, etc).
This generic servlet base class has no dependency on the Spring ApplicationContext
concept. Simple servlets usually don't load their own context but rather access service beans from the Spring root application context, accessible via the filter's ServletContext
(see WebApplicationContextUtils
).
The FrameworkServlet
class is a more specific servlet base class which loads its own application context. FrameworkServlet serves as direct base class of Spring's full-fledged DispatcherServlet
.
public abstract class FrameworkServlet
Base servlet for Spring's web framework. Provides integration with a Spring application context, in a JavaBean-based overall solution.
spring web Framework鐨勫熀紜 servlet聽 錛屾彁渚涘湪浠avabean涓哄熀紜鐨勬暣浣撹В鍐蟲柟妗堝凡瀹屾垚涓巗pring搴旂敤涓婁笅鏂囩殑闆嗘垚
This class offers the following functionality:
1.綆$悊涓涓猻ervlet涓涓綉緇滃簲鐢ㄤ笂涓嬫枃瀹炰緥錛岃繖涓猻ervlet鐨勯厤緗敱servlet鍛藉悕絀洪棿閲岀殑bean鏉ュ喅瀹?br />2.鏍規嵁璇鋒眰澶勭悊鍙戝竷浜嬩歡錛屾槸鍚﹁姹傛垚鍔熺殑琚鐞嗕簡
WebApplicationContext
instance per servlet. The servlet's configuration is determined by beans in the servlet's namespace.
Subclasses must implement doService(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
to handle requests. Because this extends HttpServletBean
rather than HttpServlet directly, bean properties are automatically mapped onto it. Subclasses can override initFrameworkServlet()
for custom initialization.
鍥犱負瀹冪戶鎵胯嚜httpservletBean 鎵浠ean鐨勫睘鎬у凡緇忚鑷姩鐨勮閰嶄簡錛屽瓙綾誨彲浠ラ氳繃瑕嗙洊initFrameworkServlet鏉ュ畾鍒跺垵濮嬪寲bean
Detects a "contextClass" parameter at the servlet init-param level, falling back to the default context class, XmlWebApplicationContext
, if not found. Note that, with the default FrameworkServlet, a custom context class needs to implement the ConfigurableWebApplicationContext
SPI.
Passes a "contextConfigLocation" servlet init-param to the context instance, parsing it into potentially multiple file paths which can be separated by any number of commas and spaces, like "test-servlet.xml, myServlet.xml". If not explicitly specified, the context implementation is supposed to build a default location from the namespace of the servlet.
Note: In case of multiple config locations, later bean definitions will override ones defined in earlier loaded files, at least when using Spring's default ApplicationContext implementation. This can be leveraged to deliberately override certain bean definitions via an extra XML file.
The default namespace is "'servlet-name'-servlet", e.g. "test-servlet" for a servlet-name "test" (leading to a "/WEB-INF/test-servlet.xml" default location with XmlWebApplicationContext). The namespace can also be set explicitly via the "namespace" servlet init-param.
<bean id="exampleInitBean" class="examples.ExampleBean" init-method="cleanup"/>
setBeanName
setBeanClassLoader
setBeanFactory
setResourceLoader
(only applicable when running in an application context)setApplicationEventPublisher
(only applicable when running in an application context)setMessageSource
(only applicable when running in an application context)setApplicationContext
(only applicable when running in an application context)setServletContext
(only applicable when running in a web application context)postProcessBeforeInitialization
methods of BeanPostProcessorsafterPropertiesSet
postProcessAfterInitialization
methods of BeanPostProcessors destroy
Method Summary | |
---|---|
聽boolean | containsBean(String聽name) 聽聽聽聽聽聽聽聽聽聽Does this bean factory contain a bean with the given name? |
聽String[] | getAliases(String聽name) 聽聽聽聽聽聽聽聽聽聽Return the aliases for the given bean name, if any. |
聽Object | getBean(String聽name) 聽聽聽聽聽聽聽聽聽聽Return an instance, which may be shared or independent, of the specified bean. |
聽Object | getBean(String聽name, Class聽requiredType) 聽聽聽聽聽聽聽聽聽聽Return an instance, which may be shared or independent, of the specified bean. |
聽Class | getType(String聽name) 聽聽聽聽聽聽聽聽聽聽Determine the type of the bean with the given name. |
聽boolean | isPrototype(String聽name) 聽聽聽聽聽聽聽聽聽聽Is this bean a prototype? |
聽boolean | isSingleton(String聽name) 聽聽聽聽聽聽聽聽聽聽Is this bean a shared singleton? |
聽boolean | isTypeMatch(String聽name, Class聽targetType) 聽聽聽聽聽聽聽聽聽聽Check whether the bean with the given name matches the specified type. |
public interface Lifecycle
Interface defining methods for start/stop lifecycle control. The typical use case for this is to control asynchronous processing.
Can be implemented by both components (typically a Spring bean defined in a Spring BeanFactory
) and containers (typically a Spring ApplicationContext
). Containers will propagate start/stop signals to all components that apply.
Can be used for direct invocations or for management operations via JMX. In the latter case, the MBeanExporter
will typically be defined with an InterfaceBasedMBeanInfoAssembler
, restricting the visibility of activity-controlled components to the Lifecycle interface.
ConfigurableApplicationContext
, AbstractMessageListenerContainer
, SchedulerFactoryBean
Method Summary | |
---|---|
聽boolean
|
isRunning
()
聽聽聽聽聽聽聽聽聽聽Check whether this component is currently running. |
聽void
|
start
()
聽聽聽聽聽聽聽聽聽聽Start this component. |
聽void
|
stop
()
聽聽聽聽聽聽聽聽聽聽Stop this component. |
|