av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

idea將maven項目改成Spring boot項目的方法步驟

瀏覽:2日期:2023-09-25 17:32:49

1、添加parent父級依賴

在pom.xml文件中,要首先添加parent父級依賴

<!-- 這個parent是springboot的父級依賴, 它提供相關的starter的maven管理以及版本號管理,還有相關maven插件的公共配置 --><parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --></parent>

2、添加spring-boot-starter核心依賴和測試依賴

在dependencies中,添加spring-boot-starter核心依賴,并添加核心測試依賴

<dependencies> <!-- 這是springboot的核心starter,它將完成起步依賴,自動配置,日志,YAML配置等功能 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <!-- 測試依賴 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency></dependencies>

3、添加properties屬性配置

properties屬性配置主要是存放依賴的版本號,可以自定義,相對于定義了一個變量

<properties> <!-- 指定jdk版本 --> <java.version>1.8</java.version> <!-- druid連接池版本 --> <druid.version>1.1.17</druid.version></properties><dependencies> <!-- alibaba開發的druid連接池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <!-- 對應properties中的<druid.version> --> <version>${druid.version}</version> </dependency></dependencies>

4、添加build打包插件配置

<!-- spring boot打包插件,主要將spring boot應用打包成jar文件或者war文件 --><build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins></build>

5、搭建入口類

Spring boot項S目一般都有一個*Application.java的入口類,里面有一個main的方法,這是標準Java應用程序的入口方法。

@SpringBootApplicationpublic class TestApplication(){ public static void main(String[] args){ SpringApplication.run(TestApplication.class, args); }}

在main方法中執行的Spring Application的run方法,返回一個上下文的容器實例

public static void main(String[] args) { //SpringApplication的run方法返回一個上下文的容器實例 ApplicationContext context = SpringApplication.run(TestApplication.class, args); //從容器獲取bean對象 UserService service = context.getBean(UserServiceImpl.class); service.say();}

@SpringBootApplication注解是Spring boot的核心注解,它是一個組合注解,主要包含以下注解:

1、@SpringBootConfiguration:這是Spring boot項目的配置注解,這也是一個組合注解

@Target({ElementType.TYPE})@Retention(RetentionPolicy.RUNTIME)@Documented@Configurationpublic @interface SpringBootConfiguration { @AliasFor( annotation = Configuration.class ) boolean proxyBeanMethods() default true;}

2、@EnableAutoConfiguration:啟用自動配置,該注解會使Spring boot根據項目中依賴的jar包自動配置項目的配置項

3、@ComponentScan:默認掃描@SpringBootApplication所在類的同級目錄以及它的子目錄。

如果Spring boot項目中整合了SpringMVC,那么就需要添加一個注解@MapperScan,這個注解的作用是告訴容器dao包中的接口的路徑,使得可以在運行時動態代理生成實現類并放入到容器中管理。

@SpringbootApplication@MapperScan({'edu.nf.ch01.user.dao', 'edu.nf.ch01.product.dao'})public class TestApplication(){ public static void main(String[] args){ SpringApplication.run(TestApplication.class, args); }}

6、application配置文件在resource目錄中創建一個application.properties文件或者application.yml(推薦)文件,對項目的相關配置都可以在這個文件中配置。

idea將maven項目改成Spring boot項目的方法步驟

7、搭建測試環境

在test目錄下創建測試類,在類名上加@SpringBootTest注解,在測試類中還可以注入bean,Spring boot會完成自動注入。

@SpringBootTestpublic class UsersTest(){ @AutoWired private UserService service; @Test void testUser(){ ... }}

到此這篇關于idea將maven項目改成Spring boot項目的方法步驟的文章就介紹到這了,更多相關idea maven改成Springboot內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
主站蜘蛛池模板: 视频1区 | 久久久久久成人 | 亚洲乱码一区二区 | 国产小视频在线观看 | 噜噜噜色网| 国内精品免费久久久久软件老师 | 99re热精品视频 | 亚洲欧美一区二区三区视频 | 中文字幕一区二区三区不卡 | 六月成人网 | 在线观看中文字幕av | 一级黄色生活视频 | 久久中文字幕电影 | 夜夜夜夜夜夜曰天天天 | 成人亚洲网 | 精品久久国产 | www视频在线观看 | 亚av在线 | 久久久久九九九女人毛片 | 免费视频一区二区 | 国产激情综合五月久久 | 青青草中文字幕 | 久久久久久久久淑女av国产精品 | 一区二区在线不卡 | 欧美精品一区三区 | 精品久久国产 | 亚洲成人精选 | 国产精品日本一区二区在线播放 | 久久久av | 国产女人叫床高潮大片免费 | 成人在线视频免费观看 | 日本特黄a级高清免费大片 国产精品久久性 | 国产一区不卡 | 国产毛片毛片 | 成人在线免费网站 | 日本精品视频在线观看 | 中文字幕二区三区 | 成人免费大片黄在线播放 | 免费毛片www com cn | 国内精品久久精品 | 亚洲精品成人av |