初识springboot
来源:互联网 发布:mac怎么更改用户名称 编辑:程序博客网 时间:2024/06/02 06:55
Springboot:
spring旗下的全新框架,指在简化spring,springmvc繁琐的配置,提高开发效率,从而使开发不再需要样板化的配置,成为热门的快速开发的领导者
springboot的特点:(需要jdk1.7以上版本运行)
1. 创建独立的Spring应用程序
Spring Boot可以以jar包的形式来运行,运行一个Spring Boot项目我们只需要通过Java -jar xx.jar类运行。非常方便
2. 嵌入的Tomcat,无需部署WAR文件:Spring Boot可以内嵌Tomcat,这样我们无需以war包的形式部署项目
3. 简化Maven配置:使用Spring或者SpringMVC我们需要添加大量的依赖,而这些依赖很多都是固定的,这里Spring Boot 通过starter能够帮助我们简化Maven配置
4. 自动配置Spring:事务,注解,在springboot中一个注解搞定,@SpringBootAppalication:自动添加 spring.xml文件 并且配置 自动扫描,自动添加web.xml 同时 在web.xml 配置过滤器 拦截器,@EnableTransactionManagement 表示启动全局事务支持
全局类:
/** * 自动添加 spring.xml文件 并且配置 自动扫描 * 自动添加web.xml 同时 在web.xml 配置过滤器 拦截器 * * @EnableTransactionManagement 表示启动全局事务支持 用MVC设计时,还需要在服务层加上@Transactional注解,表示启用了事务,同时在查询方法上@Transactional(readOnly=true) */@EnableTransactionManagement@SpringBootApplicationpublic class Helloboot{//@Action(value="hello")//public String Hello() throws IOException{//ServletActionContext.getResponse().getOutputStream().write("hello springboot and struts2".getBytes());//return null;//}public static void main(String[] args) {SpringApplication.run(Helloboot.class, args);}}
5. 提供生产就绪型功能,如指标,健康检查和外部配置
6. 绝对没有代码生成和对XML没有要求配置
附加:
1,.springboot的ioc,即spring的bean容器,实现如下,两个注解
/** * 相当于标示 该类是一个bean的容器 * @author Administrator * */@Configurationpublic class BeanContainer {/** * 表示调用该方法产生一个bean * 方法名是bean的id * @return */@Beanpublic User userTest(){return new User();}}自定义的dbcp数据源:
@Configurationpublic class BeanContainer {//<context:property-placeholder location="classpath:/jdbc.properties"/>@ConfigurationProperties(prefix="mydbcp")@Beanpublic DataSource basicDataSource(){BasicDataSource basicDataSource = new BasicDataSource(); return basicDataSource;}}
2.appalication.properties,springboot的核心配置文件
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:orclspring.datasource.username=scottspring.datasource.password=123456spring.datasource.driver-class-name=oracle.jdbc.OracleDriver# level 日志级别#‘logging.level.*=LEVEL’ where ‘LEVEL’ is one of TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFFlogging.level.root=INFOlogging.level.org.springframework.web=INFOlogging.level.org.hibernate=DEBUG#自己引入的数据源mydbcp.url=jdbc:oracle:thin:@localhost:1521:orclmydbcp.username=scottmydbcp.password=123456mydbcp.driverClassName=oracle.jdbc.OracleDriver3,mybatis和springboot,集成,maven依赖
<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>cn.et</groupId> <artifactId>SpringbootTest</artifactId> <version>0.0.1-SNAPSHOT</version> <!-- Inherit defaults from Spring Boot --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.4.RELEASE</version> </parent> <!-- Add typical dependencies for a web application --> <dependencies> <!-- 表示可以发布一个web应用,启动一个tamcat --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency><!-- 添加转译jsp的依赖 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId><scope>provided</scope></dependency><dependency><groupId>org.apache.tomcat.embed</groupId><artifactId>tomcat-embed-jasper</artifactId><scope>provided</scope></dependency><!-- jpa,操作数据源的入口 --><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId></dependency><dependency><groupId>cn.et</groupId> <artifactId>ojdbc6</artifactId> <version>6</version><scope>system</scope><systemPath>C:\app\Administrator\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar</systemPath></dependency><!-- dbcp数据源 --><dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId></dependency><!-- struts2有关的包 --><dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId> <version>2.3.28</version></dependency><dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-spring-plugin</artifactId> <version>2.3.28</version></dependency><dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-convention-plugin</artifactId> <version>2.3.28</version></dependency><!-- mybatis集成 该包在mybatis官网--><dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.2.1</version></dependency><!-- jsonlib与ajax --><dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>1.1</version> <classifier>jdk15</classifier></dependency> </dependencies> <build/></project>
阅读全文
0 0
- 初识Springboot
- 初识 SpringBoot
- 初识springboot
- 初识springboot
- 初识springboot
- 1.SpringBoot系列-初识SpringBoot
- springboot相关(初识)
- 1、初识SpringBoot
- SpringBoot 使用fastjson初识
- springBoot初识demo
- SpringBoot开发详解(一)--初识SpringBoot
- springboot系列文章(一)-初识springboot
- SpringBoot入门(七)-初识WebSocket
- springboot【1】入门之初识
- SpringBoot初识和快速入门(一)
- 初识springboot——jpa注解映射
- 1、Spring Boot学习笔记:初识springboot
- 初识SpringBoot,Mavern之环境搭建
- BZOJ1483 梦幻布丁 —— 链表启发式合并
- js正则exec,match,search用法练习
- Android Bitmap操作内存问题总结(图片处理、截屏等)
- AndroidStudio运行项目出现This version of Android Studio is incompatible with the Gradle Plugin used.
- Mac终端Iterm2快捷键大全
- 初识springboot
- 看看安东尼詹姆斯
- Codeforces832B Petya and Exam
- Android之调用系统分享
- Spring4.3x教程之二SpEL表达式的使用
- A
- camder的安装及设置
- 利用R语言画出两地路线图
- nginx日志