maven笔记-3-springboot小案例
来源:互联网 发布:ae软件手机版中文 编辑:程序博客网 时间:2024/06/15 10:02
1.创建spring boot项目:
2.maven update后JRE System中的jre还原问题
3.将maven项目打成jar包
1.创建spring boot项目:
此时看到JRE System Library[这里的版本可能不是你系统当中的]
设置方法:http://blog.csdn.net/u011095110/article/details/56279020
配置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>springboots</groupId> <artifactId>springboottest</artifactId> <version>0.0.1-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.1.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies></project>
此时查看可以看到
写入ExampleApplication类
package springbootpackage;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class ExampleApplication { //SpringApplication是springBoot框架中描述spring应用的类 //它的run()方法会创建一个spring应用上下文(ApplicationContext) //另一个方面它会扫描当前路径上的依赖 //发现spring-webmvc (由spring-boot-starter-web传递引入)在类路径中,那么 //springboot会判断这是一个web应用,并启动一个内嵌的servlet容器(默认的是tomcat) public static void main(String[] args) { SpringApplication.run(ExampleApplication.class, args); }}
ExampleController类
package springbootpackage;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestController@RequestMapping("/Example")public class ExampleController { @RequestMapping("/") public String home(){ return "你好,同学"; } //带参数的方法处理 @RequestMapping("/{myName}") public String home(@PathVariable String myName){ return "你好,同学"+myName; }}
springboot的启动方法(因为springboot自带tomcat,所以不需要引入tomcat)
1.执行ExampleApplication(直接run as–>java Application)
2.利用run as –> Maven build输入命令spring-boot:run执行
注:Maven build当该项目只设置了一条命令,便默认执行那条命令,如果有多条命令,选择执行。Maven build… 多条命令的设置方式
2.将项目打成jar包
点击maven build…设置命令clean package执行,如果看到下面错误
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project springboottest: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
设置eclipse中对应的为jdk路径
此时打成的jar中没有项目的jar文件,在pom.xml中配置
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
再次打成jar包即可
到项目的jar文件对应的地方按住shift+鼠标右键,选择在此处打开命令窗口
运行java -jar 对应的jar包文件名.jar便可执行
- maven笔记-3-springboot小案例
- Maven构建springBoot Demo案例
- eclipse+maven+springboot小Demo
- SpringBoot任务调度案例(学习笔记)
- SpringBoot使用JdbcTemplate案例(学习笔记)
- 【学习笔记】 使用Maven+SSM框架 + MySQL写一个小案例
- maven-小白入门学习笔记3
- maven小笔记
- 日常小笔记-maven
- maven标签小笔记
- 使用springBoot框架+maven+mybatis 实现的小demo
- SpringBoot和MyBatis集成案例(学习笔记)
- SpringBoot热部署之devtools案例(学习笔记)
- Maven学习笔记(九)案例背景
- maven笔记-2-springmvc/spring案例
- SpringBoot小白教程 (一): 使用Maven新建SpringBoot工程
- SpringBoot小白教程 (一): 使用Maven新建SpringBoot工程
- opencl初学笔记--经典初学小案例
- C++ 获取路径下文件、文件夹
- HTML标题
- 反转链表
- Notepad++ 正则快速替换 占位符
- Codeforces 392-C Yet Another Number Sequence (矩阵快速幂)
- maven笔记-3-springboot小案例
- 2017多校联合第8场1008/hdu 6140Hybrid Crystals(思维)
- MyBatis之java.lang.UnsupportedOperationException异常解决方案
- Tomcat(2)生命周期管理
- 前端框架Easey UI(二)表格控件的查找与删除操作消息提示对话框
- NYOJ 79 拦截导弹
- POJ cow acrobats
- 《Java源码分析》:ConcurrentHashMap JDK1.8
- iOS MermaidSwimming(美人鱼游泳)~demo