360SDN.COM

Spring boot 使用jpa集成 mysql

来源:  2017-08-17 17:01:19    评论:0点击:

spring boot 集成MySQL数据库也很简单。之前在创建demo one时候 我使用了 H2 数据库,这里将对H2 lib的应用替换成对mysql 相关lib的引用。需要注释掉

 

	<!--<dependency>-->
   		<!--<groupId>com.h2database</groupId>-->
   		<!--<artifactId>h2</artifactId>-->
   		<!--<scope>runtime</scope>-->
	<!--</dependency>-->
    加上这个
<dependency>  <groupId>mysql</groupId>  <artifactId>mysql-connector-java</artifactId>  </dependency> 
	
   	不要以为这样就好了,要连接的数据库的帐号、密码同样要找个地方放,不然咱们伟大的程序也没法去和数据库接吻。因此需要在application.properties文件里面填上这些必要的信息如下:	

 

# ===============================  # = DATA SOURCE  # ===============================   # Set here configurations for the database connection   # Connection url for the database "netgloo_blog"
# 经常梦想中彩票,因此建立个彩票数据库-cp,最大单注中过10块
spring.datasource.url = jdbc:mysql://localhost:3306/cp?useSSL=false
	# Username and password	spring.datasource.username = root	
	spring.datasource.password = 1	
	# Keep the connection alive if idle for a long time (needed in production)	
	spring.datasource.testWhileIdle = true	spring.datasource.validationQuery = SELECT 1	
	# ===============================	
	# = JPA / HIBERNATE	
	# ===============================	
	# Use spring.jpa.properties.* for Hibernate native properties (the prefix is	
	# stripped before adding them to the entity manager).	
	# Show or not log for each sql query	
	spring.jpa.show-sql = true	
	# Hibernate ddl auto (create, create-drop, update): with "update" the database	
	# schema will be automatically updated accordingly to java entities found in	
	# the project	
	spring.jpa.hibernate.ddl-auto = update	
	# Naming strategy	
	spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy	
	# Allows Hibernate to generate SQL optimized for a particular DBMS	
	spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect


	自此尽管去run吧


来源:http://blog.csdn.net/yellow_beard/article/details/51813486
为您推荐

友情链接 |九搜汽车网 |手机ok生活信息网|ok生活信息网|ok微生活
 Powered by www.360SDN.COM   京ICP备11022651号-4 © 2012-2016 版权