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
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