springboot的简单配置helloworld
1.pom.xml的配置(加入几个常用和必须用的jar包)
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
<version>1.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
</dependencies>
2.配置文件application-dev.properties 含MySQL配置信息,不使用 可忽略
spring.datasource.url=jdbc:mysql://localhost:3306/s2sm_sales
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.mvc.view.prefix = /pages/
spring.mvc.view.suffix=.jsp
3.激活文件配置项文件application.properties
spring.profiles.active=dev
4.controller的书写
@RestController
@Configuration
public class Helloworld {
@RequestMapping("/hello")
public static String index() {
return "Hello World";
}
}
5.程序入口
@SpringBootApplication
public class SpringBootApplication1 {
public static void main(String[] args) {
SpringApplication.run(SpringBootApplication1.class, args);
}
}
6.注意:controller的类必须在程序入口的包以及子包下,否则扫描不到