首页 > 编程语言 > 详细

使用spring-boot 加速企业开发

时间:2016-01-23 02:10:27      阅读:254      评论:0      收藏:0      [点我收藏+]

Spring-boot 的使用 方便了Spring 项目的管理和维护

1 建立基本项目:?https://start.spring.io/?

?

??
bubuko.com,布布扣

?

可以选择 web, jpa ,mysql . ?点击 Genarate Project 下载 .

?

2 导入 Eclipse 项目?

? ?解压下载的ZIp 文件到目录, 打开 Eclipse 选择 Import Existing Maven Project?

? ?
bubuko.com,布布扣
?

? ? 点击 Next 选择 刚才解压的目录,导入就可以了。

?

3 目录说明:

? ?

bubuko.com,布布扣
?
?static 缺省的静态文件目录。

?templates 是模板目录。 项目缺省使用 ?thymeleaf 模板技术

?

3 ?运行:?

? ? ?找到 DemoApplication ?点击右键,Run as Application 就可以了。 缺省地使用Tomcat ,大家可以使用

? ?http://127.0.0.1:8080/ ? 访问

4 去掉Tomcat ,加入Jetty?

? ? ??

?

<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-tomcat</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

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

?

?

5 加入 thymeleaf?

? ??

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

?6 加入 Mysql ,和 bibernate 支持

?

? ??

<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<scope>runtime</scope>
		</dependency>

?修改 application.properties 在 resources 目录下。

?

? ??

? ??

写道
spring.datasource.url = jdbc:mysql://localhost:3306/test
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.driverClassName = com.mysql.jdbc.Driver

# Specify the DBMS
spring.jpa.database = MYSQL
# Show or not log for each sql query
spring.jpa.show-sql = true
# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto = update
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# stripped before adding them to the entity manager)
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext

?

完整的连接数据库测试:

?

1 建立数据库 ,Mysql 的。? ?

写道

CREATE TABLE `wp_site` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`NAME` varchar(100) DEFAULT NULL,
`STATUS` varchar(50) DEFAULT NULL,
`CREATE_DATE` datetime DEFAULT NULL,
`CREATE_USER` varchar(50) DEFAULT NULL,
`description` varchar(500) DEFAULT NULL,
`domain_name` varchar(500) DEFAULT NULL,
`upload_path` varchar(500) DEFAULT NULL,
`title_img` varchar(500) DEFAULT NULL,
`site_path` varchar(500) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

?测试路径: ?http://127.0.0.1:8080/greeting/test

?

? ? ? ? ?
bubuko.com,布布扣
?

完整项目代码 ?GitHub 下载:

?

? ? ?https://github.com/guanry/wmshop.git

?

?

?

?

使用spring-boot 加速企业开发

原文:http://guanxi.iteye.com/blog/2272620

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!