欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

IDEA+Maven創(chuàng)建Spring項(xiàng)目的實(shí)現(xiàn)步驟

 更新時(shí)間:2020年07月02日 14:45:43   作者:小白開(kāi)  
這篇文章主要介紹了IDEA+Maven創(chuàng)建Spring項(xiàng)目的實(shí)現(xiàn)步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

這篇隨筆搭建的工程是普通的Spring工程,用于學(xué)習(xí)Spring框架,如果要搭建SpringMVC工程,可以參考另一篇

第一步:在IDEA點(diǎn)擊new -> project

左側(cè)選擇Maven,直接點(diǎn)擊Next。第一次使用IDEA的朋友,頂部還要選擇Project SDK路徑,就是Java的安裝路徑。

這里隨便填一下之后點(diǎn)擊Next

選擇項(xiàng)目存放路徑,或者保持默認(rèn),點(diǎn)擊Finish,來(lái)到工程頁(yè)面之后,在項(xiàng)目文件夾上右鍵并選擇Add Framework Support

在這個(gè)頁(yè)面找一下Spring,打鉤。點(diǎn)擊OK

完成后,會(huì)下載Spring的jar包,并存放在項(xiàng)目的lib目錄下。

下載完成之后創(chuàng)建一個(gè)簡(jiǎn)單的項(xiàng)目。

四個(gè)Java文件一個(gè)appContext.xml我貼在這里

public class Student {

  private String name;
  private Homework homework;
  public Student(){}
  public Student(String name, Homework homework) {
    this.name = name;
    this.homework = homework;
  }

  public void doHomeWork(){
    System.out.println(homework.getContent());
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public Homework getHomework() {
    return homework;
  }

  public void setHomework(Homework homework) {
    this.homework = homework;
  }
}
public class Homework {

  private String content;

  public Homework(){}
  public Homework(String content) {
    this.content = content;
  }

  public String getContent() {
    return content;
  }

  public void setContent(String content) {
    this.content = content;
  }
}
public class Homework {

  private String content;

  public Homework(){}
  public Homework(String content) {
    this.content = content;
  }

  public String getContent() {
    return content;
  }

  public void setContent(String content) {
    this.content = content;
  }
}
import java.util.Date;

public class CheckNowTime {

  public void beforDoHomework(){
    System.out.println(new Date(System.currentTimeMillis()));
  }
}
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {

  public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("appContext.xml");
    Student student = context.getBean(Student.class);

    System.out.println(student.getName()+"準(zhǔn)備做作業(yè)了");
    student.doHomeWork();

    context.close();

  }
}
<?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:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
  <!-- 讓Spring管理 Student bean  -->
  <bean id="student" class="demo1.Student">
    <property name="name" value="小明"></property>
    <property name="homework" ref="homework"></property>
  </bean>

  <!-- 讓Spring管理Homework bean-->
  <bean id="homework" class="demo1.Homework">
    <property name="content" value="how to calc 3+2 ?"></property>
  </bean>

  <!-- 切面定義-->
  <bean id="checktime" class="demo1.CheckNowTime"></bean>
  <aop:config>
    <aop:aspect ref="checktime">
      <aop:pointcut id="dohomework" expression="execution(* *.doHomeWork(..))"/>
      <aop:before pointcut-ref="dohomework" method="beforDoHomework"></aop:before>
    </aop:aspect>
  </aop:config>
</beans>

因?yàn)槔又惺褂肧pring AOP,所以還需要引入一個(gè)jar包。我的pom.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>test</artifactId>
  <version>1.0-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjweaver</artifactId>
      <version>1.9.4</version>
    </dependency>
  </dependencies>

</project>

然后你就可以運(yùn)行自己的Spring項(xiàng)目啦,main方法在App類里面。

到此這篇關(guān)于IDEA+Maven創(chuàng)建Spring項(xiàng)目的實(shí)現(xiàn)步驟的文章就介紹到這了,更多相關(guān)IDEA+Maven創(chuàng)建Spring內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 詳解JAVA 抽象類

    詳解JAVA 抽象類

    這篇文章主要介紹了JAVA 抽象類的相關(guān)資料,文中講解非常細(xì)致,幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-07-07
  • Java網(wǎng)絡(luò)編程三要素及通信程序詳解

    Java網(wǎng)絡(luò)編程三要素及通信程序詳解

    這篇文章主要介紹了Java網(wǎng)絡(luò)編程三要素及通信程序詳解,Java網(wǎng)絡(luò)編程是在網(wǎng)絡(luò)通信協(xié)議下,實(shí)現(xiàn)網(wǎng)絡(luò)互連的不同計(jì)算機(jī)上運(yùn)行的程序間可以進(jìn)行數(shù)據(jù)交換,需要的朋友可以參考下
    2023-07-07
  • Java中的HashMap為什么會(huì)產(chǎn)生死循環(huán)

    Java中的HashMap為什么會(huì)產(chǎn)生死循環(huán)

    這篇文章主要介紹了Java中的HashMap為什么會(huì)產(chǎn)生死循環(huán),HashMap?死循環(huán)是一個(gè)比較常見(jiàn)、比較經(jīng)典的問(wèn)題,下面文章我們就來(lái)徹底理解死循環(huán)的原因。需要的小伙伴可以參考一下
    2022-05-05
  • SpringBoot項(xiàng)目創(chuàng)建使用+配置文件+日志文件詳解

    SpringBoot項(xiàng)目創(chuàng)建使用+配置文件+日志文件詳解

    Spring的出現(xiàn)是為了簡(jiǎn)化 Java 程序開(kāi)發(fā),而 SpringBoot 的出現(xiàn)是為了簡(jiǎn)化 Spring 程序開(kāi)發(fā),這篇文章主要介紹了SpringBoot項(xiàng)目創(chuàng)建使用+配置文件+日志文件,需要的朋友可以參考下
    2023-02-02
  • Java中循環(huán)冗余校驗(yàn)(CRC32)的實(shí)現(xiàn)

    Java中循環(huán)冗余校驗(yàn)(CRC32)的實(shí)現(xiàn)

    CRC校驗(yàn)實(shí)用程序庫(kù)在數(shù)據(jù)存儲(chǔ)和數(shù)據(jù)通訊領(lǐng)域,為了保證數(shù)據(jù)的正確,就不得不采用檢錯(cuò)的手段,下面這篇文章主要給大家介紹了關(guān)于Java中循環(huán)冗余校驗(yàn)(CRC32)實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。
    2017-10-10
  • 關(guān)于junit測(cè)試需要的依賴

    關(guān)于junit測(cè)試需要的依賴

    這篇文章主要介紹了關(guān)于junit測(cè)試需要的依賴,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • JPA中@ElementCollection使用示例詳解

    JPA中@ElementCollection使用示例詳解

    在JPA中,@ElementCollection注解主要用于映射集合屬性,例如List、Set或數(shù)組等集合屬性,以及Map結(jié)構(gòu)的集合屬性,每個(gè)屬性值都有對(duì)應(yīng)的key映射,這篇文章主要介紹了JPA中@ElementCollection使用,需要的朋友可以參考下
    2023-11-11
  • Mybatis配置文件之動(dòng)態(tài)SQL配置備忘錄

    Mybatis配置文件之動(dòng)態(tài)SQL配置備忘錄

    這篇文章主要介紹了Mybatis配置文件之動(dòng)態(tài)SQL配置備忘錄的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • 基于Java實(shí)現(xiàn)計(jì)數(shù)排序,桶排序和基數(shù)排序

    基于Java實(shí)現(xiàn)計(jì)數(shù)排序,桶排序和基數(shù)排序

    這篇文章主要為大家詳細(xì)介紹了計(jì)數(shù)排序,桶排序和基數(shù)排序的多種語(yǔ)言的實(shí)現(xiàn)(JavaScript、Python、Go語(yǔ)言、Java),感興趣的小伙伴可以了解一下
    2022-12-12
  • SpringBoot解析自定義yml文件的流程步驟

    SpringBoot解析自定義yml文件的流程步驟

    這篇文章主要介紹了SpringBoot解析自定義yml文件的流程步驟,文章通過(guò)代碼示例和圖文結(jié)合的方式給大家介紹的非常詳細(xì), 對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下
    2024-06-06

最新評(píng)論