Maven工程 springboot demo(打包方式jar)

1.pom.xml 配置

<parent>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-parent</artifactId>

<version>1.4.0.RELEASE</version>

  </parent> 

  <dependencies>

    <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-web</artifactId>

    </dependency>
  </dependencies>

2.变更默认的jdk版本

  <properties>   
    <java.version>1.7</java.version>
  </properties>

3.update Maven project

4.创建引导类

package cn.itdx.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}

@SpringBootApplication其实就是以下三个注解的总和

@Configuration: 用于定义一个配置类

@EnableAutoConfiguration :Spring Boot会自动根据你jar包的依赖来自动配置项目。

@ComponentScan告诉Spring 哪个packages 的用注解标识的类会被spring自动扫描并且装入bean容器。

5.运行


6.用SpringBoot 写个helloworld

package cn.itdx.demo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloWorldController {
	@RequestMapping("/info")
	public String info(){
		return "HelloWorld";		
	}		
}

7.修改tomcat启动端口

在src/main/resources下创建application.properties

server.port=8088
8. 读取配置文件信息

在src/main/resources下的application.properties 增加配置

url=http://www.itdx.cn
测试

@Autowired
	private Environment env;

	@RequestMapping("/info")
	public String info(){
		return "HelloWorld~~"+env.getProperty("url");
	}

9.热部署

<dependency>  
	    <groupId>org.springframework.boot</groupId>  
	    <artifactId>spring-boot-devtools</artifactId>  
	</dependency>  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值