idea(自備 ide 技能均可)
進入 Spring 官網點擊 【Start a new Spring Project】直達
推薦選擇 grandle, 配置文件清爽不少
各個組件Web: 集成 SpringMVCSecurity:JPA:Actuator:Thymeleaf:MySQL:Lombok:HSQLDB:
SpringBoot 1.4.2 文檔
解壓后到目錄下改 build.gradle 中 elipse 為 idea,這是因為我用的 idea, eclipse 的話應該不用改,不過我沒試過。然后直接在目錄下執行
╰─$ ./gradlew idea完成后便可以直接用 idea 打開了
記得要 使用 import

點擊 Finish 完成,等ok。。。
啟動
運行 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).啟動失敗,問題是缺少數據庫配置
解決:在 application.properties 里加數據庫配置,自己在 MySQL 里新建一個數據庫。application.properties 中內容如下:
spring.datasource.url=jdbc:mysql://localhost:3306/daxuespring.datasource.username=rootspring.datasource.passWord=123qwe# update 模式會自動建表,有改動后也會更新,不過不會刪原來的東西spring.jpa.properties.hibernate.hbm2ddl.auto=updatespring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialectspring.jpa.properties.hibernate.connection.release_mode=autoOK,啟動完畢看結果
此時目錄結構如下
╰─$ 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沒有 MySQL ? 木有關系,這么辦
更改一下依賴再刷新即可hslqdb 是一個內存數據庫,一般用來測試用,在使用 JPA 的方式下可以無縫切換到 MySQL。沒有 MySQL 的環境可以暫時頂用一下。
再次啟動
訪問 http://localhost:8080
SpringSecurity 的默認基本安全配置,密碼請在啟動的日志中自行尋找。
目標達成!

新聞熱點
疑難解答