简单! springboot 项目,访问返回 Hello SpringBoot !

springboot 项目,访问返回 Hello SpringBoot !

准备
  • 浏览器
  • jdk8uploading...
  • idea(自备 ide 技能均可)

    新建项目

    进入 Spring 官网
    点击 【Start a new Spring Project】
    直达

推荐选择 grandle, 配置文件清爽不少

选择如下

简单介绍

各个组件
Web: 集成 SpringMVC
Security:
JPA:
Actuator:
Thymeleaf:
Mysql:
Lombok:
HSQLDB:

SpringBoot 1.4.2 文档

Idea 导入

解压后到目录下改 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 NONE

Action:

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/daxue
spring.datasource.username=root
spring.datasource.password=123qwe

# update 模式会自动建表,有改动后也会更新,不过不会删原来的东西
spring.jpa.properties.hibernate.hbm2ddl.auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.jpa.properties.hibernate.connection.release_mode=auto

OK,启动完毕看结果

此时目录结构如下

╰─$ 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 的默认基本安全配置,密码请在启动的日志中自行寻找。

目标达成!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值