1. applicationContext.xmlをばねグローバルコンフィギュレーションファイルは、ばね特性を制御するために使用されます
ディスパッチャ-servlet.xmlはコントローラ内部のスプリングMVC、インターセプトURI前方図であります
applicationContext.xmlをファイルを使用する場合にはweb.xmlにリスナーを追加する必要があります
どのように、スプリングユニットテストを書くときにテストを使用する2.アイデア:
最も簡単な方法は、なし(UnitTestBean)
まず、applicationContext.xmlをはSRCの下に配置する必要があります
@RunWith(BlockJUnit4ClassRunner クラス) パブリック クラスtestdemo { @Test 公共 ボイドtestdemolador(){ ApplicationContextのコンテキスト = 新しい ClassPathXmlApplicationContext( "applicationContext.xmlを" )。 testbean =(testbean)context.getBean( "testbeanを" )。 System.out.println(a.testdemolodar())。 } }
第二、applicationContext.xmlをは、WEB-INF(アイデアのデフォルト設定)に入れ
ApplicationContextのコンテキスト= 新しい ClassPathXmlApplicationContext( "WEB-INF / applicationContext.xmlを");
最も簡潔なコンテンツのインスタンスを取り付けapplicationContext.xmlを
<?xml version = "1.0"エンコード= "UTF-8"?> <豆のxmlns = "http://www.springframework.org/schema/beans" のxmlns:XSI = "http://www.w3.org / 2001 / XMLスキーマ・インスタンス」 のxsi:のschemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <ビーンID = "testbean" クラス = "bean.testbean" /> </豆>
プラスweb.xml構成は、コンテンツを添付します
<xmlのバージョン= "1.0"エンコード= "UTF-8"?> の<web-appのxmlns = "http://xmlns.jcp.org/xml/ns/j2ee" のxmlns:XSI = "のhttp:// WWW .w3.org / 2001 / XMLスキーマ・インスタンス" のxsi:schemaLocationの =" http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0 .xsd」 バージョン = "4.0"> <文脈PARAM> の<param-name>のcontextConfigLocation </ PARAM名> の<param-value>は/WEB-INF/applicationContext.xml </ PARAM値> </コンテキストPARAM > <聞き手> <listener- クラス > org.springframework.web.context.ContextLoaderListener </ listener- クラス > </リスナー> </ web-app>の