Spring Boot配置

1:Eclipse安装sts插件

通过eclipce市场安装Spring Tool Suite (STS) for Eclipse插件

安装sts插件后eclipse的navigator菜单失效,Project Explorer无法显示.

java.lang.NoClassDefFoundError: org/springframework/ide/eclipse/beans/core/model/IBeansConfig

解决方法1:卸载STS

解决方法2:待定

2:Spring Tool Suite下载地址

https://spring.io/tools/sts/legacy.

http://spring.io/tools/sts/all

一个独立的spring开发工具,一个被包装过的eclipse

Spring Boot官网:http://projects.spring.io/spring-boot/


3:通过网址安装sts插件

http://dist.springsource.com/release/TOOLS/update/e4.5/

http://dist.springsource.com/release/TOOLS/update/e3.7/


4:spring boot官方地址

http://docs.spring.io/spring-boot/docs/1.5.2.RELEASE/reference/htmlsingle/#getting-started


5:spring boot cli

执行符合spring的groovy脚本工具。可以快速搭建一个demo系统。demo使用groovy编写脚本,然后可以使用Spring CLI直接运行


6:git库

https://github.com/spring-projects/spring-boot


7:开发IDE

使用eclipse+mvn插件开发


8:配置jdbctemplate访问数据库

在application.properties中配置

spring.datasource.url=jdbc:mysql://localhost:3306/test

spring.datasource.username=root

spring.datasource.password=11111

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

在代码中引用 jdbcTemplate即可

@Autowired

private JdbcTemplate jdbcTemplate;


9:配置sessionFactory访问数据库

或者1定义

@Autowired
private EntityManagerFactory entityManagerFactory;

@Bean
public SessionFactory getSessionFactory() {
    if (entityManagerFactory.unwrap(SessionFactory.class) == null) {
        throw new NullPointerException("factory is not a hibernate factory");
    }
    return entityManagerFactory.unwrap(SessionFactory.class);
}
引用

private SessionFactory sessionFactory;
或者2在属性配置文件中配置(可有可无)

spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext

并且在java代码中编码

@Bean
public HibernateJpaSessionFactoryBean sessionFactory() {
    return new HibernateJpaSessionFactoryBean();
}
@Autowired
private SessionFactory sessionFactory;
或者3在属性配置文件中配置(可有可无)

spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext

并且在java代码中编码

@Bean
public SessionFactory sessionFactory(HibernateEntityManagerFactory hemf) {
    return hemf.getSessionFactory();
}
@Autowired
private SessionFactory sessionFactory;



Spring事务参考资料

http://docs.spring.io/spring/docs/2.5.x/reference/transaction.html

http://docs.spring.io/spring/docs/3.2.18.RELEASE/spring-framework-reference/htmlsingle/#transaction



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值