1

Spring WebMVCを使用する動的Webプロジェクトの[servlet-name]-servlet.xmlで次のBeanのクリアが取得されましたか?私はかなり多くの文書を読みましたが、それらのプロパティタグを持つ目的が何であるかを理解できませんでしたか?

<bean name="abcController" parent="defController" 
    class="abcController">
    <constructor-arg ref="staticService" />
    <property name="commandClass" value="abcCommand" />
    <property name="property2" value="search" />
    <property name="property3" value="true" />
    <property name="formView" value="/someValue" />


</bean>

プロパティがabcControllerクラスのフィールドになる可能性があることは知っていますが、abcControllerクラスにはformViewという名前のフィールドはありません。誰かが私を助けることができますか?

4

2 に答える 2

1

そのxmlファイルは、ファイル自体にフィールドをコーディングせずにフィールドを作成するために使用されます。

 // This is used to Start the ApplicationContext Container and to get the Bean of AbcCotroller

ApplicationContext context = 
new ClassPathXmlApplicationContext("[servlet-name]-servlet.xml");

abcController obj = (abcController) context.getBean("abcController");

後でコードでBeanを使用できます。

obj.getFormView(); //this will return '/somevalue'
于 2012-09-28T09:49:42.997 に答える
0
//Bean.java
 public class SampleBean{
 private String message;
 public void setMessage(String message){
     this.message=message;  //setter injection            

        }
  public void ShowMessage(){
  system.out.println("Message"+message);
       }
  }

  //Main.java
   Class Main{
     public Static Void Main(String args[]){

//TO ApplicationContext コンテナーを開始する

         ApplicationContext applicationcontext = new  ClassPathXmlApplicationCOntext("Spring.xml");
  //To Read the SampleBean
        Object o=applicationcontext .getBean("SampleBean");
       SampleBean sampleBean=(SampleBean)o;
 //Invoke the Method
            sampleBean.ShowMessage();
         }
     }
//Spring.Xml

// Spring と Xml に必要な nameSpace をさらに設定する必要があります

    <bean id="sampleBean" class="SampleBean">
     <property name="message" value="this is the  use of property Tag"/>
   </bean>

   //output :This is the use or Property Tag

説明: セッター インジェクションを実行する場合は、プロパティ タグを使用します。春には、セッター インジェクションを使用する場合、セッター、コンストラクター、インターフェイス、ルックアップ メソッド インジェクションなどの依存性インジェクションがいくつかあります。最初に依存クラス オブジェクトが作成され、次に依存クラス オブジェクトが作成されます。創造された

于 2016-06-01T10:24:17.563 に答える