Spring 管理Bean(獲取Bean,初始化bean事件,自動匹配ByName······等)

1.實例化spring容器 和 從容器獲取Bean對象

實例化Spring容器常用的兩種方式:

方法一:

在類路徑下尋找配置文件來實例化容器 [推薦使用]

ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"beans.xml"});

方法二:

在文件系統路徑下尋找配置文件來實例化容器 [這種方式可以在開發階段使用]

ApplicationContext ctx = new FileSystemXmlApplicationContext(new String[]{“d:\\beans.xml“});

Spring的配置文件可以指定多個,可以通過String數組傳入。

?

當spring容器啟動后,因為spring容器可以管理bean對象的創建,銷毀等生命周期,

所以我們只需從容器直接獲取Bean對象就行,而不用編寫一句代碼來創建bean對象。

從容器獲取bean對象的代碼如下:

ApplicationContext ctx = new ClassPathXmlApplicationContext(“beans.xml”);

OrderService service = (OrderService)ctx.getBean("personService");

?

2.Spring實例化Bean的三種方式

以下是三種方式的例子:

1.使用類構造器實例化  [默認的類構造器]
<bean id=“orderService" class="cn.itcast.OrderServiceBean"/>2.使用靜態工廠方法實例化
<bean id="personService" class="cn.itcast.service.OrderFactory" factory-method="createOrder"/>
public class OrderFactory {public static OrderServiceBean createOrder(){   // 注意這里的這個方法是 static 的!return new OrderServiceBean();}
}3.使用實例工廠方法實例化:
<bean id="personServiceFactory" class="cn.itcast.service.OrderFactory"/>
<bean id="personService" factory-bean="personServiceFactory" factory-method="createOrder"/>
public class OrderFactory {public OrderServiceBean createOrder(){return new OrderServiceBean();}
}

?

3.Bean的生命周期 (Bean的作用域)

bean的scope 屬性

The scope of this bean: typically "singleton" (one shared instance, which will be returned by all calls?
to getBean with the given id), or "prototype" (independent instance resulting from each call to?
getBean).?Default is "singleton". Singletons are most commonly used, and are ideal for multi-?
threaded service objects.?Further scopes, such as "request" or "session", might be supported by?
extended bean factories (e.g. in a web environment).?Note: This attribute will not be inherited by?
child bean definitions.?Hence, it needs to be specified per concrete bean definition. Inner bean?
definitions inherit the singleton status of their containing bean definition, unless explicitly specified:?
The inner bean will be a singleton if the containing bean is a singleton, and a prototype if the?
containing bean has any other scope.

4

?

.singleton??[單例]?
eg:<bean id="personService" class="com.yinger.service.impl.PersonServiceBean" scope="singleton"></bean>

在每個Spring IoC容器中一個bean定義只有一個對象實例。

請注意Spring的singleton bean概念與“四人幫”(GoF)模式一書中定義的Singleton模式是完全不同的。

經典的GoF Singleton模式中所謂的對象范圍是指在每一個ClassLoader指定class創建的實例有且僅有一個

把Spring的singleton作用域描述成一個container對應一個bean實例最為貼切。亦即,假如在單個Spring容器內定義了某個指定class的bean,

那么Spring容器將會創建一個且僅有一個由該bean定義指定的類實例。

?

默認情況下會在容器啟動時初始化bean,但我們可以指定Bean節點的lazy-init=“true”來延遲初始化bean,這時候,只有第一次獲取bean會才初始化bean。

如:<bean id="xxx" class="cn.itcast.OrderServiceBean"?lazy-init="true"/>

如果想對所有bean都應用延遲初始化,可以在根節點beans設置default-lazy-init=“true“,如下:

<beans default-lazy-init="true“ ...>

.prototype?[原型]

每次從容器獲取bean都是新的對象。

對于prototype作用域的bean,有一點非常重要,那就是Spring不能對一個prototype bean的整個生命周期負責:容器在初始化、配置、裝飾或者是

裝配完一個prototype實例后,將它交給客戶端,隨后就對該prototype實例不聞不問了。不管何種作用域,容器都會調用所有對象的初始化生命周期回調方法。

但對prototype而言,任何配置好的析構生命周期回調方法都將不會被調用。清除prototype作用域的對象并釋放任何prototype bean所持有的昂貴資源,

都是客戶端代碼的職責。(讓Spring容器釋放被prototype作用域bean占用資源的一種可行方式是,通過使用bean的后置處理器,該處理器持有要被清除的bean的引用。)

以下的三種scope只是在web應用中才可以使用

.request

.session

.global session

使用這三種配置之前要先初始化Web配置

5

?

RequestContextListenerRequestContextFilter兩個類做的都是同樣的工作: 將HTTP request對象綁定到為該請求提供服務的Thread

這使得具有request和session作用域的bean能夠在后面的調用鏈中被訪問到。

?

指定Bean的初始化方法和銷毀方法

<bean id="xxx" class="cn.itcast.OrderServiceBean"?init-method="init" destroy-method="close"/>

Spring提供了幾個標志接口(marker interface),這些接口用來改變容器中bean的行為;它們包括InitializingBeanDisposableBean

現這兩個接口的bean在初始化和析構時容器會調用前者的afterPropertiesSet()方法,以及后者的destroy()方法。

Spring在內部使用BeanPostProcessor實現來處理它能找到的任何標志接口并調用相應的方法。

如果你需要自定義特性或者生命周期行為,你可以實現自己的?BeanPostProcessor

初始化回調和析構回調:

67

?

測試:

bean對象:

package com.yinger.service.impl;public class PersonServiceBean implements com.yinger.service.PersonService{//構造器public PersonServiceBean(){System.out.println("instance me");}//save方法public void save() {System.out.println("save");}//初始化方法,這個方法是類被實例化了之后就會執行的!public void init(){System.out.println("init");}//銷毀方法public void destroy(){System.out.println("destroy");}}

?

JUnit Test:

package com.yinger.test;import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;import com.yinger.service.PersonService;public class SpringTest {@BeforeClasspublic static void setUpBeforeClass() throws Exception {}@Test  //創建的單元測試public void testSave() {AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");System.out.println("--------");PersonService ps = (PersonService)ctx.getBean("personService");ps.save();ctx.close(); //有了這一句才會有destroy方法的調用}}

beans.xml 設置:

如果lazy-init(默認是default,也就是false)沒有設置,或者設置為default或者false

    <bean id="personService" class="com.yinger.service.impl.PersonServiceBean"scope="singleton" init-method="init" destroy-method="destroy"lazy-init="false"></bean>

那么結果是:

log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
instance me
init
--------
save
destroy

反之,如果設置為true,結果是:

log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
--------
instance me
init
save
destroy

?

修改測試代碼:

    @Testpublic void testSave() {AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
//        System.out.println("--------");PersonService ps = (PersonService)ctx.getBean("personService");PersonService ps1 = (PersonService)ctx.getBean("personService");System.out.println(ps==ps1);
//        ps.save();ctx.close();}

重新測試:

log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
instance me
init
true
destroy

[在scope為singleton時,每次使用getBean得到的都是同一個bean,同一個對象]

修改bean中的scope屬性:scope="prototype"

測試結果:

log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
instance me
init
instance me
init
false

[在scope為prototype時,每次得到的bean對象都是不同的,從上面可以看出實例化了兩個對象,最終的比較是false]

?

4.依賴注入

來自Spring參考文檔:依賴注入(DI)背后的基本原理是對象之間的依賴關系(即一起工作的其它對象)只會通過以下幾種方式來實現:構造器的參數、工廠方法的參數,

或給由構造函數或者工廠方法創建的對象設置屬性。因此,容器的工作就是創建bean時注入那些依賴關系。

相對于由bean自己來控制其實例化、直接在構造器中指定依賴關系或者類似服務定位器(Service Locator)模式這3種自主控制依賴關系注入的方法來說,

控制從根本上發生了倒轉,這也正是控制反轉(Inversion of Control, IoC)?名字的由來。

?

(1)基本類型的注入:

基本類型對象注入:
<bean id="orderService" class="cn.itcast.service.OrderServiceBean"><constructor-arg index=“0type=“java.lang.Stringvalue=“xxx/>//構造器注入<property name=“namevalue=“zhao/>//屬性setter方法注入
</bean>注入其他bean:
方式一
<bean id="orderDao" class="cn.itcast.service.OrderDaoBean"/>
<bean id="orderService" class="cn.itcast.service.OrderServiceBean"><property name="orderDao" ref="orderDao"/>
</bean>方式二(使用內部bean,但該bean不能被其他bean使用)
<bean id="orderService" class="cn.itcast.service.OrderServiceBean"><property name="orderDao"><bean class="cn.itcast.service.OrderDaoBean"/></property>
</bean>

?

測試 構造器和setter 方式注入:

新建一個DAO的接口:

package com.yinger.dao;public interface PersonDao {public void save();}

新建一個接口的實現類:

package com.yinger.dao.impl;import com.yinger.dao.PersonDao;public class PersonDaoBean implements PersonDao{public void save() {System.out.println("PersonDaoBean.save()");}}

修改原有的PersonServiceBean,添加兩個字段:

package com.yinger.service.impl;import com.yinger.dao.PersonDao;
import com.yinger.service.PersonService;public class PersonServiceBean implements PersonService{private PersonDao pDao;//這樣設計就實現了業務層和數據層的徹底解耦private String name;//默認的構造器public PersonServiceBean(){System.out.println("instance me");}//帶參數的構造器public PersonServiceBean(PersonDao pDao){this.pDao=pDao;}//帶參數的構造器public PersonServiceBean(PersonDao pDao,String name){this.pDao=pDao;this.name=name;}//save方法public void save() {
//        System.out.println("save");pDao.save();System.out.println(this.getName());}//初始化方法,這個方法是類被實例化了之后就會執行的!public void init(){System.out.println("init");}//銷毀方法public void destroy(){System.out.println("destroy");}public String getName() {return name;}public void setName(String name) {this.name = name;}}

修改beans.xml:

    <bean id="personService" class="com.yinger.service.impl.PersonServiceBean"><constructor-arg index="0"><bean id="pDao" class="com.yinger.dao.impl.PersonDaoBean"></bean></constructor-arg><constructor-arg index="1" type="java.lang.String" value="name" /></bean>

新增一個測試方法:

    @Testpublic void testInjection() {AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");System.out.println("--------");PersonService ps = (PersonService)ctx.getBean("personService");ps.save();ctx.close();}

測試結果:

log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
--------
PersonDaoBean.save()
name

?

如果在beans.xml中再添加一句:

<property name="name" value="name2"></property>

重新測試,結果是:

log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
--------
PersonDaoBean.save()
name2

?

(2)集合類型的注入:

集合類型的裝配:

public class OrderServiceBean {private Set<String> sets = new HashSet<String>();private List<String> lists = new ArrayList<String>();private Properties properties = new Properties();private Map<String, String> maps = new HashMap<String, String>();....//這里省略屬性的getter和setter方法
}

XML配置:

<bean id="order" class="cn.itcast.service.OrderServiceBean"><property name="lists"><list><value>lihuoming</value></list></property>        <property name="sets"><set><value>set</value></set></property>        <property name="maps"><map><entry key="lihuoming" value="28"/></map></property>        <property name="properties"><props><prop key="12">sss</prop></props></property>
</bean>

?

補充:Spring對泛型的支持

2

?

(3)三種依賴注入的方式 和 兩種裝配方式:

①使用構造器注入

②使用屬性setter方法注入:

通過調用無參構造器或無參static工廠方法實例化bean之后,調用該bean的setter方法,即可實現基于setter的DI。

Spring開發團隊提倡使用setter注入。而且setter DI在以后的某個時候還可將實例重新配置(或重新注入)

③使用Field注入(用于注解方式)

?

處理bean依賴關系通常按以下步驟進行:

  1. 根據定義bean的配置(文件)創建并初始化BeanFactory實例(大部份的Spring用戶使用支持XML格式配置文件的BeanFactoryApplicationContext實現)。

  2. 每個bean的依賴將以屬性、構造器參數、或靜態工廠方法參數的形式出現。當這些bean被實際創建時,這些依賴也將會提供給該bean。

  3. 每個屬性或構造器參數既可以是一個實際的值,也可以是對該容器中另一個bean的引用。

  4. 每個指定的屬性或構造器參數值必須能夠被轉換成特定的格式或構造參數所需的類型。默認情況下,Spring會以String類型提供值轉換成各種內置類型,?
    比如intlongStringboolean等。

?

<constructor-arg/><property/>元素內部還可以使用ref元素。該元素用來將bean中指定屬性的值設置為對容器中的另外一個bean的引用。

注意:內部bean中的scope標記及idname屬性將被忽略。內部bean總是匿名的且它們總是prototype模式的。同時將內部bean注入到包含該內部bean之外的bean是可能的。

?

注入依賴對象可以采用手工裝配或自動裝配,在實際應用中建議使用手工裝配,因為自動裝配會產生未知情況,開發人員無法預見最終的裝配結果。

1.手工裝配依賴對象

2.自動裝配依賴對象

?

<1>手工裝配

手工裝配依賴對象,在這種方式中又有兩種編程方式

1. 在xml配置文件中,通過在bean節點下配置,如

<bean id="orderService" class="cn.itcast.service.OrderServiceBean"><constructor-arg index=“0type=“java.lang.Stringvalue=“xxx/>//構造器注入<property name=“namevalue=“zhao”/>//屬性setter方法注入</bean>

2. 在java代碼中使用@Autowired或@Resource注解方式進行裝配。但我們需要在xml配置文件中配置以下信息:

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"//注意這里,要添加的,還有下面的兩個紅色部分xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsd"><context:annotation-config/>
</beans>

這個配置隱式注冊了多個對注釋進行解析處理的處理器:AutowiredAnnotationBeanPostProcessor,

CommonAnnotationBeanPostProcessor,PersistenceAnnotationBeanPostProcessor,RequiredAnnotationBeanPostProcessor

注:?@Resource注解在spring安裝目錄的lib\j2ee\common-annotations.jar

?

* 注解方式的講解

在java代碼中使用@Autowired或@Resource注解方式進行裝配,這兩個注解的區別是:
@Autowired 默認按類型裝配,@Resource默認按名稱裝配,當找不到與名稱匹配的bean才會按類型裝配。@Autowired private PersonDao  personDao;//用于字段上@Autowiredpublic void setOrderDao(OrderDao orderDao) {//用于屬性的setter方法上this.orderDao = orderDao;}
@Autowired注解是按類型裝配依賴對象,默認情況下它要求依賴對象必須存在,如果允許null值,可以設置它required屬性為false。
如果我們想使用按名稱裝配,可以結合@Qualifier注解一起使用。如下:@Autowired  @Qualifier("personDaoBean")private PersonDao  personDao;
注:@Autowired 注解可以使用在很多地方,包括了 集合類型,Map,來自ApplicationContext的特殊類型的所有 beans等等
特殊的情況:多個構造器
雖然當 一個類只有一個連接構造器時它將被標記為 required, 但是還是可以標記多個構造器的。在這種情況下,每一個構造器都有可能被認為是連接構造器, 
Spring 將會把依賴關系能夠滿足的構造器認為是greediest 的構造器
?
?
測試:@Autowired注解 [如果兩個構造器都使用了該注解會報錯!所以,在多個構造器的情況下,要多多考慮]
新建一個PersonServiceBean2類:其中有三處使用了 @Autowired注解 ,只要其中一個位置包含了注解就行[測試時]
package com.yinger.service.impl;import org.springframework.beans.factory.annotation.Autowired;import com.yinger.dao.PersonDao;
import com.yinger.service.PersonService;public class PersonServiceBean2 implements PersonService{//Autowired默認是按照類型來裝配,這里是放在字段上@Autowired private PersonDao pDao;//這樣設計就實現了業務層和數據層的徹底解耦//默認的構造器public PersonServiceBean2(){System.out.println("instance me");}//帶參數的構造器@Autowired //放在構造方法上public PersonServiceBean2(PersonDao pDao){this.pDao=pDao;}//save方法public void save() {pDao.save();}//初始化方法,這個方法是類被實例化了之后就會執行的!public void init(){System.out.println("init");}//銷毀方法public void destroy(){System.out.println("destroy");}public PersonDao getpDao() {return pDao;}@Autowired //放在屬性的setter上public void setpDao(PersonDao pDao) {this.pDao = pDao;}}
?
beans.xml:
    <context:annotation-config/><bean id="personService2" class="com.yinger.service.impl.PersonServiceBean2"></bean><bean id="personDao" class="com.yinger.dao.impl.PersonDaoBean"></bean>

測試方法:

    @Test  //用于測試依賴注入的方法public void testInjection() {AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");System.out.println("--------");PersonService ps = (PersonService)ctx.getBean("personService2");ps.save();ctx.close();}

測試結果:

log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
--------
PersonDaoBean.save()

?

從結果中可以看出,PersonDao是注入進去了!

[還有一個要注意,按照類型查找,并不是類型一定要完全吻合,可以是屬性(字段,方法參數)的實現類(如果以上的是接口),上面的實例就是一個例子]

?
@Resource注解和@Autowired一樣,也可以標注在字段或屬性的setter方法上,但它默認按名稱裝配。
名稱可以通過@Resource的name屬性指定,如果沒有指定name屬性,當注解標注在字段上,
即默認取字段的名稱作為bean名稱尋找依賴對象,當注解標注在屬性的setter方法上,即默認取屬性名作為bean名稱尋找依賴對象。 [推薦使用的方式]@Resource(name=“personDaoBean”)private PersonDao  personDao;//用于字段上注意:如果沒有指定name屬性,并且按照默認的名稱仍然找不到依賴對象時, @Resource注解會回退到按類型裝配。
但一旦指定了name屬性,就只能按名稱裝配了。

?

測試: 測試時使用下面的一個注解就可以了

新建類PersonServiceBean3:

package com.yinger.service.impl;import javax.annotation.Resource;import com.yinger.dao.PersonDao;
import com.yinger.service.PersonService;public class PersonServiceBean3 implements PersonService{//Resource默認是按照名稱來裝配,這里是放在字段上@Resource private PersonDao pDao;//這樣設計就實現了業務層和數據層的徹底解耦//默認的構造器public PersonServiceBean3(){System.out.println("instance me");}//帶參數的構造器public PersonServiceBean3(PersonDao pDao){this.pDao=pDao;}//save方法public void save() {pDao.save();}//初始化方法,這個方法是類被實例化了之后就會執行的!public void init(){System.out.println("init");}//銷毀方法public void destroy(){System.out.println("destroy");}public PersonDao getpDao() {return pDao;}@Resource //放在屬性的setter上public void setpDao(PersonDao pDao) {this.pDao = pDao;}}

?

beans.xml中的配置:

    <context:annotation-config/><bean id="personService3" class="com.yinger.service.impl.PersonServiceBean3"></bean><bean id="pDao" class="com.yinger.dao.impl.PersonDaoBean"></bean>

測試結果:

log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
instance me
--------
PersonDaoBean.save()

?

注:beans.xml中第二個bean的id也可以是其他的名稱,例如personDao,同樣是上面的結果,因為

如果沒有指定name屬性,并且按照默認的名稱仍然找不到依賴對象時, @Resource注解會回退到按類型裝配。

?

<2>自動裝配:

對于自動裝配,大家了解一下就可以了,實在不推薦大家使用。例子:

<bean id="..." class="..."?autowire="byType"/>

autowire屬性取值如下:

byType:按類型裝配,可以根據屬性的類型,在容器中尋找跟該類型匹配的bean。如果發現多個,那么將會拋出異常。如果沒有找到,即屬性值為null。

byName:按名稱裝配,可以根據屬性的名稱,在容器中尋找跟該屬性名相同的bean,如果沒有找到,即屬性值為null。

constructor與byType的方式類似,不同之處在于它應用于構造器參數。如果在容器中沒有找到與構造器參數類型一致的bean,那么將會拋出異常。

autodetect:通過bean類的自省機制(introspection)來決定是使用constructor還是byType方式進行自動裝配。如果發現默認的構造器,那么將使用byType方式。

你也可以針對單個bean設置其是否為被自動裝配對象。當采用XML格式配置bean時,<bean/>元素的?autowire-candidate屬性可被設為false,這樣容器在查找自動裝配對象時將不考慮該bean。

3

?

5. 通過在classpath自動掃描方式把組件納入spring容器中管理

前面的例子我們都是使用XML的bean定義來配置組件。在一個稍大的項目中,通常會有上百個組件,如果這些這組件采用xml的bean定義來配置,

顯然會增加配置文件的體積,查找及維護起來也不太方便。spring2.5為我們引入了組件自動掃描機制,他可以在類路徑底下尋找標注了@Component、

@Service、@Controller、@Repository注解的類,并把這些類納入進spring容器中管理。

它的作用和在xml文件中使用bean節點配置組件是一樣的。要使用自動掃描機制,我們需要打開以下配置信息:

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsd"><context:component-scan base-package="cn.itcast"/>
</beans>

其中base-package為需要掃描的包(含子包)。

@Service用于標注業務層組件、 @Controller用于標注控制層組件(如struts中的action)、@Repository用于標注數據訪問組件,即DAO組件。而@Component泛指組件,當組件不好歸類的時候,我們可以使用這個注解進行標注。

?

測試:

在上面的例子中,添加如下內容:

@Service("personService3")
public class PersonServiceBean3 implements PersonService{

@Repository
public class PersonDaoBean implements PersonDao{

同時,在beans.xml中添加:

    <context:component-scan base-package="com.yinger.dao.impl"></context:component-scan><context:component-scan base-package="com.yinger.service.impl"></context:component-scan>

測試方法不變,結果還是一樣:

log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
instance me
--------
PersonDaoBean.save()

轉載于:https://www.cnblogs.com/4wei/archive/2012/12/25/2847238.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/260132.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/260132.shtml
英文地址,請注明出處:http://en.pswp.cn/news/260132.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

directoryinfo 讀取 映射磁盤_LoaRunner性能測試系統學習教程:磁盤監控(5)

上期我們講到LoaRunner性能測試內存監控&#xff0c;這期我們講LoaRunner性能測試磁盤監控。磁盤監控在介紹磁盤監控前&#xff0c;先介紹固定磁盤存儲管理的性能&#xff0c;固定磁盤存儲器的結構層次如圖所示。每個單獨的磁盤驅動器稱為一個物理卷&#xff08;PV&#xff09;…

Eclipse新建web項目正常啟動tomcat不報錯,但不能訪問項目的解決方法

原因: 雖然我手動添加了自己下載的tomcat,但是由于在Eclipse中創建Server時&#xff0c;“Server Locations”選項采用的時默認配置&#xff0c;即"Use workspace metadata(does not modify tomcat installation ),這意味著該Server不會改變TOMCAT的安裝及部署目錄&#…

oracle10g執行insert,oracle 10g 增強審計。表insert 及bind values

oracle 10g之前&#xff0c;可以審計對表的操作&#xff0c;但不能記錄操作時的各個列的值。在10g中&#xff0c;已經可以審核并監控到具體的sql語句及內容了。要求10g以后的版本。alter system set audit_traildb_extended scopespfile;[more]示例&#xff1b;SQL> show us…

點擊按鈕 變換圖片

<html xmlns"http://www.w3.org/1999/xhtml"><head><meta http-equiv"Content-Type" content"text/html; charsetutf-8" /><title>變換圖片</title><script type"text/javascript">function chan…

[鄰接表] 學習鄰接表的表示方法+BFS

算法導論上面的偽代碼實現哦&#xff0c;沒啥技術&#xff0c;不過這個鄰接表表示法&#xff08;figo大神教的&#xff09;很nice。 簡單說一下&#xff0c;head里面是放著自己節點后面鏈的最后一個元素在邊池中的位置&#xff0c;邊池里面成一個一個鏈狀&#xff0c;像并查集&…

wordpress漏洞_WordPress XSS漏洞可能導致遠程執行代碼(RCE)

原作者&#xff1a; Ziyahan Albeniz在2019年3月13日&#xff0c;專注于靜態代碼分析軟件的RIPS科技公司發布了他們在所有版本的WordPress 5.1.1中發現的跨站點腳本(XSS)漏洞的詳細信息。該漏洞已在不同類別的各種網站上公布。有些人將其歸類為跨站點請求偽造(CSRF)漏洞&#x…

centOS 6環境下安裝R-3.3.2及Rstudio-server

【編譯R語言】 1、下載安裝R語言 # 下載R-3.3.2 $ wget https://cran.r-project.org/src/base/R-3/R-3.3.2.tar.gz# 安裝R-3.3.2 $ tar -zxvf R-3.3.2.tar.gz $ cd R-3.3.2# 安裝到默認目錄下 --perfix/opt/R 或 /usr/local/lib64/R $ ./configure --prefix/opt/R --with-re…

DJ輪回舞曲網下載教程

該網站網址為&#xff1a;http://www.92cc.com/ 昨天有網友問我這個網站能不能下載。我告訴他&#xff0c;只要能在線試聽的就能下載 于是今天出個臨時教程 教大家如何獲取試聽的音樂URL。 第一步找到試聽的網址&#xff0c;如&#xff1a; http://www.92cc.com/p97206.html 第…

【DP】【Asia - Harbin - 2010/2011】【Permutation Counting】

【題目描述】Given a permutation a1, a2,...aN of {1, 2,..., N}, we define its E-value as the amount of elements where ai > i. For example, the E-value of permutation {1, 3, 2, 4} is 1, while the E-value of {4, 3, 2, 1} is 2. You are requested to find h…

三豐三坐標編程基本步驟_三豐三坐標CRYSTA APEX S776

日本三豐MITUTOYO從1934年成立至今&#xff0c;專力致于精密測量儀器的研發和生產&#xff0c;在七十多年中&#xff0c;日本三豐量具MITUTOYO已成為世界最大綜合測量儀器的制造商&#xff0c;它生產的產品包括千分尺&#xff0c;卡尺&#xff0c;千分表&#xff0c;高度尺&…

oracle的文件后綴名,轉:數據文件的擴展名是ora,dbf,dat的,有什么區別?

只是通過擴展名來標識文件的類型而已&#xff0c;對于數據文件不管是ora/dat/dbf&#xff0c;都是一樣的&#xff0c;沒有什么區別。.dbf-數據文件&#xff0c; .tmp-臨時文件&#xff0c;.log-重作日志文件(redo log file)&#xff0c; .ctl-控制文件.ora-參數文件&#xff0c…

Unity3D研究院之Android同步方法讀取streamingAssets

版本Unity5.3.3 Android 小米pad1 首先非常感謝 守著陽光 同學在下面的留言。讓我解決了一個大的謎團。。 開始我知道 StreamingAssets 路徑是這個 path “jar:file://” Application.dataPath “!/assets/”; 文檔在這里&#xff1a; http://docs.unity3d.com/Manual/Strea…

Codeforces Round 261 Div.2 D Pashmak and Parmida's problem --樹狀數組

題意&#xff1a;給出數組A&#xff0c;定義f(l,r,x)為A[]的下標l到r之間&#xff0c;等于x的元素數。i和j符合f(1,i,a[i])>f(j,n,a[j])&#xff0c;求有多少對這樣的(i,j). 解法&#xff1a;分別從左到右&#xff0c;由右到左預處理到某個下標為止有多少個數等于該下標&…

JQuery AJAX提交中文亂碼的解決方案

$.post(doSearch.action, {page : page,vip : vip,searchType : searchType,subtype : subtype,type : type,contentType: "application/x-www-form-urlencoded; charsetutf-8", keyword : keyword}, function(data) //回傳函數{var val;}); 解決這個中文亂碼問題&am…

列舉ospf的5種報文類型_危險品貨物各種包裝類型以及裝箱技巧

對于危險貨物來說&#xff0c;其危險性的大小除與貨物的本身性質有關外&#xff0c;還與貨物的包裝方式密切相關。因而&#xff0c;危險貨物進箱條件的確定&#xff0c;也必須考慮到貨物的包裝方法。一、集裝箱內徑20GP內徑&#xff1a;長5.8M*寬2.34M*高2.34M40GP內徑&#xf…

linux一行多個命令行,如何在一行中運行多個Linux命令

對于每個Linux管理員來說&#xff0c;熟練使用各種命令行是他們的特性。但對于普通用戶來說&#xff0c;可能還是有難度&#xff0c;您需要繼續練習Linux命令&#xff0c;并找到使該任務更有效的方法。實現這個特定目標的一種方法是學習一些技巧&#xff0c;這些技巧可以提高發…

Java 數組基礎

數組 數組&#xff08;Array&#xff09;&#xff1a;相同類型數據的集合。 定義數組 方式1&#xff08;推薦&#xff0c;更能表明數組類型&#xff09; type[] 變量名 new type[數組中元素的個數]; 比如&#xff1a; int[] a new int[10]; 數組名&#xff0c;也即引用a&…

車輛跟馳模型matlab代碼實現_MATLAB——考慮駕駛員特性及前車速度的快速路模型...

重發一下之前誤刪的一篇~目前大多數元胞自動機模型并沒有考慮前車速度&#xff0c;大多數同向行駛的模型中車輛都是處在一個完全跟車的狀態&#xff0c;無論前車是加速還是減速&#xff0c;后車駕駛者都只是根據自己的車速判斷是減速跟馳還是變換車道來尋求尋求更合理的行駛狀態…

linux nc命令

參考 :http://www.linuxso.com/command/nc.html NC 全名 Netcat (網絡刀)&#xff0c;作者是 Hobbit && ChrisWysopal。因其功能十分強大&#xff0c;體積小巧而出名&#xff0c;又被大家稱為“瑞士軍刀”。nc - TCP/IP swiss army knife nc 常用于溢出、反向鏈接、上傳…

收藏一些自己認為好的網站或博客

月光博客 seo每天一貼 虎嗅網 李巖的博客 中郵閱讀網&#xff0c;專門看電子期刊的&#xff0c;很不錯的免費閱讀期刊網。 seay web安全技術博客: http://www.cnseay.com 陸陸續續編輯中... 轉載于:https://www.cnblogs.com/caoyuanzhanlang/archive/2013/01/05/2846086.html