Java Spring のクイックスタート

高洛峰
リリース: 2017-01-23 11:09:14
オリジナル
1540 人が閲覧しました

1. Spring とは何ですか?

Spring は、エンタープライズレベルのアプリケーション開発を簡素化するために生まれました。これまでは EJB しか実現できなかった機能を実現できます。

Spring は、IOC (DI) および AOP コンテナー フレームワークです。

2. Spring の詳細な説明

軽量: Spring は非侵入的です - Spring に基づいて開発されたアプリケーションのオブジェクトは Spring の API に依存できません

Dependency Injection: (DI-Dependency Injection、IOC)

アスペクト指向プログラミング: (AOP アスペクト指向プログラミング)

コンテナ: Spring は、アプリケーション オブジェクトのライフ サイクルを含み、管理するため、コンテナです

フレームワーク: Spring では、複雑なアプリケーションに結合するための単純なコンポーネント構成の使用を Spring で実装します。 XML と Java アノテーションを使用して組み合わせることができます

ワンストップ: IOC と AOP に基づいて、エンタープライズ アプリケーション用のさまざまなオープンソース フレームワークと優れたサードパーティ クラス ライブラリを統合できます (実際、Spring 自体も SpringMVC をプレゼンテーション層と永続化層 Spring JDBC)

3. Spring 環境を構築する

1. Eclipse で Spring Tool Suite をインストールする

SPRING TOOL SUITE は、Spring ベースのアプリケーションをより便利に開発するために使用できる Eclipse プラグインですEclipse プラットフォーム上で。

2. パッケージを追加します。

次の jar パッケージをプロジェクトのクラスパスに追加します。

Java Spring快速入门3. Spring 構成ファイル: 通常の Spring プロジェクトでは、For を使用して 1 つ以上の Bean 構成ファイルを作成する必要があります。 Spring IOC コンテナで Bean を構成します。 Bean 設定ファイルは、クラスパスまたは他のディレクトリに配置できます。

4. Spring プロジェクトを確立し、HelloWorld を作成します:

package com.atguigu.spring.beans;
public class HelloWorld {
  private String name;
  public void setName(String name) {
    System.out.println("setName...");
    this.name = name;
  }
  public void hello(){
    System.out.println("Hello " + name);
  }
  public HelloWorld() {
    System.out.println("HelloWorld's construct...");
  }
}
ログイン後にコピー
<?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:util="http://www.springframework.org/schema/util"
  xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans             
http://www.springframework.org/schema/beans/spring-beans.xsd        
 http://www.springframework.org/schema/util 
 http://www.springframework.org/schema/util/spring-util-4.0.xsd">
  <bean id="helloworld" class="com.atguigu.spring.beans.HelloWorld">
    <property name="name" value="spring"></property>
  </bean>
</beans>
ログイン後にコピー
package com.atguigu.spring.beans;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main {
  public static void main(String[] args) {
    /*
    HelloWorld helloWorld = new HelloWorld();
    helloWorld.setName("spring");
    helloWorld.hello();
    */
    //1.创建容器
    ApplicationContext ctx = new   ClassPathXmlApplicationContext("appliactionContext.xml");
    //2.从容器中获取bean
    HelloWorld hello = (HelloWorld) ctx.getBean("helloworld");
    //3.调用bean的方法
    hello.hello();
  }
}
ログイン後にコピー

5. テスト結果

この記事の内容が少しでも役立つことを願っています。皆さんの勉強や仕事、そしてPHP中国語ウェブサイトをサポートしたいと思っています! Java Spring快速入门

Java Spring クイック スタートに関連するその他の記事については、PHP 中国語 Web サイトに注目してください。

関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!