MyeClipse2017は、参照用のSpringプロジェクトを作成しました。特定のコンテンツは次のとおりです
1. Webプロジェクトを作成します
2。プロジェクトを右クリックします - >プロパティ
3。スプリングを検索 - > PeojectFacets->右側のスプリングを見つけて、チェックして保存します
4。テスト
4.1クラスを作成します
パッケージcn.spring.user;/**** @author dzsom* @date 2018年3月13日11:42:03 pm* @encoding utf-8* @version 1.0 **/public class user {private string uname;プライベートインクエイジ; public string getuname(){return uname; } public void setuname(string uname){this.uname = uname; } public int getage(){return age; } public void Setage(int age){this.age = age; }}4.2 SRCで構成ファイルApplicationContext.xmlを変更します
<?xml version = "1.0" encoding = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/xmlschema-instance" xmlns:p = "http://www.springframework.org/schema/p" xsi:schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd "> <! - スプリング管理にオブジェクトを残してください - > <bean name =" user "> </bean> </bean> </beans>
4.3テストクラスを作成する(@Testでは、Junitパッケージをインポートする必要があります)
パッケージcn.spring.test; Import org.junit.test; Import org.springframework.context.applicationcontext; Import org.springframework.context.support.classpathxmlapplicationcontext; Import cn.spring.user.user;/**** @author 9:35:19 AM* @Encoding UTF-8* @version 1.0 **/public class demo {@test public void fun(){// 1。コンテナオブジェクトを作成するApplicationContext AC = new ClassPathXMLApplicationContext( "ApplicationContext.xml"); // 2。オブジェクトユーザーのコンテナに尋ねるユーザー=(ユーザー)ac.getbean( "user"); // 3。 print System.out.println(user); }}4.4右クリックしてテストを実行します。値出力がある場合、スプリングは正常に構築されます。
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。