hibernate使用时遇到的小问题

来源:互联网 发布:java sys refcursor 编辑:程序博客网 时间:2024/05/25 18:11

1.@Value取不到值:

@Value取不到值引出的spring的2种配置文件applicationContext.xml和xxx-servlet.xml

项目中经常会用到配置文件,定义成properties的形式比较常见,为了方便使用一般在spring配置文件中做如下配置:

<context:property-placeholder ignore-unresolvable="true" location="classpath*:/application.properties" />
  • 1
  • 1

这样在程序代码中直接用@Value(“${name}”)就能直接取到properties文件中定义的变量值.

其中,applicationContext.xml为spring配置文件,xxx-servlet.xml为spring-mvc配置文件。@Value取不到值的问题,现在的可以清楚由于Controller是定义在springmvc的servlet配置文件中的,查找,故只需要将placeholder重新在springmvc的配置中配置一遍,Controller中的@Value注解便能取到值了.

2.延迟加载的时候,报coudnt get session 的错误

在xml配置文件中将对应的controller地址加到spring mvc的管理中。

3.xxx type error

在生成的bean文件中,注解要么全放在属性域上面,要么全放在getxxx()方法域上面,不能在一个bean中,存在两种情况。

学习文章:
《hibernate注解》http://www.cnblogs.com/sevenlin/p/sevenlin_sprindatajpa20150725.html
《hibernate与jpa关系》http://blog.sina.com.cn/s/blog_5f1619e80100yoxz.html#cmt_2897777
0 0
原创粉丝点击