Sprint Boot 打Jar包并启动

来源:互联网 发布:freehand mx for mac 编辑:程序博客网 时间:2024/06/03 23:06

pom.xml

<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.yunfeng</groupId>  <artifactId>YFEidApi</artifactId>  <version>1</version>  <packaging>jar</packaging>  <parent>       <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-parent</artifactId>        <version>0.5.0.M7</version>  </parent>    <dependencies>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-web</artifactId>        </dependency>        <dependency>            <groupId>org.thymeleaf</groupId>            <artifactId>thymeleaf-spring3</artifactId>        </dependency>        <dependency>        <groupId>org.apache.tomcat</groupId>        <artifactId>tomcat-servlet-api</artifactId>        <version>9.0.0.M22</version>        <scope>provided</scope>        </dependency>    </dependencies>    <properties>        <start-class>com.eid.controller.App</start-class>    </properties>    <build>        <plugins>            <plugin>                <groupId>org.springframework.boot</groupId>                <artifactId>spring-boot-maven-plugin</artifactId>            </plugin>            <plugin>                <groupId>org.apache.maven.plugins</groupId>            <artifactId>maven-compiler-plugin</artifactId>            <configuration>              <source>1.8</source>              <target>1.8</target>            </configuration>          </plugin>        </plugins>    </build>    <repositories>        <repository>            <id>spring-milestone</id>            <url>http://repo.spring.io/libs-milestone</url>            <snapshots>                <enabled>false</enabled>            </snapshots>        </repository>    </repositories>    <pluginRepositories>        <pluginRepository>            <id>spring-milestone</id>            <url>http://repo.spring.io/libs-milestone</url>            <snapshots>                <enabled>false</enabled>            </snapshots>        </pluginRepository>    </pluginRepositories></project>

App.java

package com.eid.controller;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.context.annotation.ComponentScan;@ComponentScan@EnableAutoConfigurationpublic class App {    public static void main(String[] args) {    System.out.println("Start App Class....");        SpringApplication.run(App.class, args);    }}

TestController.java

package com.eid.controller;import org.springframework.boot.SpringApplication;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class TestController {    @RequestMapping("/t1")    public String  showPerson() {        return "test";    }}


App.java和TestController.java放到 package里:com.eid.controller。名字要用controller


启动 Java -jar xxx.jar

原创粉丝点击