Solution to hibernate configuration file path parsing error when exporting Jar from package under Maven

Encountered hibernate configuration file path resolution error when configuring a local project maven project

Configuration method

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource">
			<ref local="dataSource" />
		</property>
		<property name="mappingDirectoryLocations">
			<value>hibernate-mappings</value>
		</property>
...

 The IDE runs normally, but after packaging it into a jar, an error is reported, the content is as follows

wrote
Caused by: java.io.FileNotFoundException: class path resource [hibernate-mappings] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/Users/bowstringyu/IdeaProjects/INMS/AutoDiscovery/target/ABC-1.0-SNAPSHOT.jar!/hibernate-mappings

 Obviously, the mappingDirectoryLocation specified path of conventional configuration does not support jar file path reading when packaged into jar

 

Solution 1: Use maven-resources-plugins to modify the default output path, point the configuration file to the outside of the jar package, and then add the path to the classpath. I think this configuration is troublesome, so I didn't try it. If you are interested, you can try it.

 

Solution 2: I think Spring will not be so stupid, and there must be a way to support jar output. I tried the mappingResources+list configuration and directly pointed to the *.hbm.xml file in the path.

The IDE runs normally, and it passed after packaging the jar.

A relatively elementary question, I hope to save some time for friends who are new to maven who also encounter this problem

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326773967&siteId=291194637