idea(自備 ide 技能均可)
進(jìn)入 Spring 官網(wǎng)點(diǎn)擊 【Start a new Spring Project】直達(dá)
推薦選擇 grandle, 配置文件清爽不少

各個(gè)組件Web: 集成 SpringMVCSecurity:JPA:Actuator:Thymeleaf:MySQL:Lombok:HSQLDB:
SpringBoot 1.4.2 文檔
解壓后到目錄下改 build.gradle 中 elipse 為 idea,這是因?yàn)槲矣玫?idea, eclipse 的話(huà)應(yīng)該不用改,不過(guò)我沒(méi)試過(guò)。然后直接在目錄下執(zhí)行
╰─$ ./gradlew idea完成后便可以直接用 idea 打開(kāi)了
記得要 使用 import

點(diǎn)擊 Finish 完成,等ok。。。
啟動(dòng)
運(yùn)行 Daxueapplication.java
2017-01-05 09:01:27.132 WARN 53547 --- [ main] o.s.boot.SpringApplication : Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available)2017-01-05 09:01:27.138 ERROR 53547 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : ***************************APPLICATION FAILED TO START***************************Description:Cannot determine embedded database driver class for database type NONEAction:If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).啟動(dòng)失敗,問(wèn)題是缺少數(shù)據(jù)庫(kù)配置
解決:在 application.properties 里加數(shù)據(jù)庫(kù)配置,自己在 MySQL 里新建一個(gè)數(shù)據(jù)庫(kù)。application.properties 中內(nèi)容如下:
spring.datasource.url=jdbc:mysql://localhost:3306/daxuespring.datasource.username=rootspring.datasource.passWord=123qwe# update 模式會(huì)自動(dòng)建表,有改動(dòng)后也會(huì)更新,不過(guò)不會(huì)刪原來(lái)的東西spring.jpa.properties.hibernate.hbm2ddl.auto=updatespring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialectspring.jpa.properties.hibernate.connection.release_mode=autoOK,啟動(dòng)完畢看結(jié)果
此時(shí)目錄結(jié)構(gòu)如下
╰─$ tree -a.├── .gitignore├── .gradle│ └── 2.13│ └── taskArtifacts│ ├── cache.properties│ ├── cache.properties.lock│ ├── fileHashes.bin│ ├── fileSnapshots.bin│ └── taskArtifacts.bin├── build.gradle├── daxue.iml├── daxue.ipr├── daxue.iws├── gradle│ └── wrapper│ ├── gradle-wrapper.jar│ └── gradle-wrapper.properties├── gradlew├── gradlew.bat└── src ├── main │ ├── java │ │ └── cn │ │ └── dxs2s │ │ ├── DaxueApplication.java │ │ ├── domain │ │ ├── service │ │ └── web │ │ └── IndexController.java │ └── resources │ ├── application.properties │ ├── static │ └── templates └── test └── java └── cn └── dxs2s └── DaxueApplicationTests.java沒(méi)有 MySQL ? 木有關(guān)系,這么辦
更改一下依賴(lài)再刷新即可hslqdb 是一個(gè)內(nèi)存數(shù)據(jù)庫(kù),一般用來(lái)測(cè)試用,在使用 JPA 的方式下可以無(wú)縫切換到 MySQL。沒(méi)有 MySQL 的環(huán)境可以暫時(shí)頂用一下。
再次啟動(dòng)
訪(fǎng)問(wèn) http://localhost:8080
SpringSecurity 的默認(rèn)基本安全配置,密碼請(qǐng)?jiān)趩?dòng)的日志中自行尋找。
目標(biāo)達(dá)成!

新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注