springboot-maven快速配置并启动项目
2016-10-29 13:14
981 查看
from:http://www.cnblogs.com/suncj/p/4065589.html
pom.xml文件
新建Application.java
新建MainController
resources下新增application.properties
在Application.java里启动main方法(run as -- java application),页面上输入localhost:8080就可看到helloworld的页面了
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.vi</groupId> <artifactId>personal</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <!-- 继承父包 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.3.RELEASE</version> </parent> <!-- spring-boot的web启动的jar包 --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--jpa的jar包 ,操作数据库的,类似hibernate--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <!--mysql驱动--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!--thymeleaf模板jar,是很不错的html数据传递取值,类似jsp的jstl--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies> <!--maven的插件--> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> <!-- 配置java版本 不配置的话默认父类配置的是1.6--> <pluginManagement> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> </pluginManagement> </build> </project>
新建Application.java
package com.boot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @Configuration @EnableAutoConfiguration @ComponentScan public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
新建MainController
package com.boot.web; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class MainController { // @RequestMapping("") // public String index(){ // return "examples/index"; // } @RequestMapping("/") @ResponseBody String home() { return "Hello World!"; } }
resources下新增application.properties
spring.datasource.platform=mysql spring.datasource.url=jdbc:mysql://localhost/springboot?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&autoReconnect=true&failOverReadOnly=false spring.datasource.username=root spring.datasource.password=root spring.datasource.driverClassName=com.mysql.jdbc.Driver # Advanced configuration... spring.datasource.max-active=50 spring.datasource.max-idle=6 spring.datasource.min-idle=2 spring.datasource.initial-size=6 #create table spring.jpa.hibernate.ddl-auto=validate server.port=8080 server.session-timeout=30 server.tomcat.uri-encoding=UTF-8 spring.thymeleaf.prefix=classpath:templates/ spring.thymeleaf.suffix=.html spring.thymeleaf.mode=HTML5 spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.content-type=text/html spring.thymeleaf.cache=false
在Application.java里启动main方法(run as -- java application),页面上输入localhost:8080就可看到helloworld的页面了
相关文章推荐
- SpringBoot1-spirng项目快速搭建+maven+spring的基本配置
- 详解用Spring Boot零配置快速创建web项目
- 解决maven同步的eclipse中的springboot项目无法启动问题
- Maven快速使用教程(二) spring boot 项目构建
- Spring Boot项目在Mac下使用Maven启动时碰到的神奇问题:Unregistering JMX-exposed beans on shutdown
- 使用maven 快速搭建springboot项目
- Spring boot 项目 maven的profile多环境配置 不自动替换变量的问题解决
- 快速构建Spring Boot 1.5.8 maven Web 项目
- maven项目:spring配置里:连接远程oracle(虚拟机里),【虚拟机没开启(数据库连接不上)导致tomcat启动失败(web.xml配置Spring了监听器)】=(也不报具体错误,就是超时)
- 通过Tomcat配置、启动Springboot项目war包程序
- 使用Spring Boot +JPA+mybatis快速启动一个web项目
- springboot+maven快速构建项目
- springboot+maven快速构建项目
- 使用Spring Boot框架maven项目新建后启动失败, 提示Unregistering JMX-exposed beans on shutdown
- 详解用Spring Boot零配置快速创建web项目
- Maven配置Spring Boot项目打包,依赖包到lib目录、配置文件到conf目录
- Spring boot项目maven的profile多环境配置不自动替换变量的问题解决
- Spring boot框架项目,使用maven命令将配置文件打包到jar包外,项目运行读取jar外配置文件
- spring boot (一)入门 启动、日志配置和快速构建
- idea快速创建maven集成spring-boot项目