springbootweb 项目的简单部署

@SpringBootApplication
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages ={"com.example.demo"})
public class DemoApplication extends SpringBootServletInitializer{


public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);

}

        // 本地直接main 方法启动application,然后发布到本地tomcat 怎么启动呢?

        有源码可知在创建webapplication时候调用了 configure 方法了,加载了DemoApplication类。

 protected SpringApplicationBuilder configure(
            SpringApplicationBuilder application) {
        return application.sources(DemoApplication.class);
    }

}

@RestController
@RequestMapping("/path")
public class HelloController {
@RequestMapping("/hello")
   public void print(){
   System.out.println("you are the best");
   }
}

pom 文件 

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> 
<dependency>  
        <groupId>org.springframework.boot</groupId>  
        <artifactId>spring-boot-starter-web</artifactId>  
 </dependency>  
     <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
       <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>
        <!-- The spring-boot-devtools module can be included in any project to 
            provide additional development-time features -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>   
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

项目结构


执行mvn clean package 之后本地tomcat 部署,重点说一下 url 路径为war包解压后的工程名,

例如 http://localhost:8080/demo-0.0.1-SNAPSHOT/path/hello。 怎么创建springboot 请参考上篇博客。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值