你还可以用spring啊,启动的时候加载spring的配置文件 ,通过spring去扫描,然后通过spring获取对应的类就可以了。
ApplicationContext context = new FileSystemXmlApplicationContext(
"classpath:conf/applicationContext.xml");
RefreshReportDate refreshReportDate = (RefreshReportDate) context
.getBean("refreshReportDate");
ApplicationContext context = new FileSystemXmlApplicationContext(
"classpath:conf/applicationContext.xml");
RefreshReportDate refreshReportDate = (RefreshReportDate) context
.getBean("refreshReportDate");
“Create a directory named WORKDIR /etc/ META-INF and place the basic config-
uration file named persistence.xml”
我说错了 META-INF是无法为package名的 他还是以文件夹的形式存在的 存放在src根目录下
现在问题是怎么让这个配置文件注册进来?
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.7.Final</version>
</dependency>
包是通过maven官方下载 hibernate4.x 支持jpa标准 目前这么一个目录系统如何去监控读取的 显然不可能是目录对了就自动注册的吧?
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.0.Final</version>
</dependency>
这些包肯定是有的 要不然程序早报错了...我还是想办法从hibernate的原始配置文件入手寻找结果把
core的maven包含子maven pom 会下载 jpa api 关于jpa 我特意看了下 标准中的 文件只要在META-INF/p...xml 就会自动识别 我的程序中依然找不到unit 显然问题就在这了...
你说的应该是新建maven的目录问题把 这个不影响的,我特地试过,错误一样,因为我项目是通过转换的(我最初新建的是java项目),目录跟新建maven项目有所区别,JPA的标准应该就是在src根目录下。我现在在想它是否是在我们获取unit对象的时候去读取配置文件获取持久化对象,还是在项目启动的时候就自动装载好然后获取的对象...
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.7.Final</version>
</dependency>单独添加即生效 非常感谢您的回答