java.lang.IllegalArgumentException: Mapping directory location[url ...]does not denote a directory

错误全部信息为:Caused by: java.lang.IllegalArgumentException: Mapping directory location [URL [file:/C:/apache-tomcat-6.0.30/webapps/SSH_Basic/WEB-INF/classes/com/student/model/Student.hbm.xml]] does not denote a directory

 

原因:

ApplicationContext.xml中配置hibernate配置有三种方式

如果配置错了、把mappingDirectoryLocations value配置成了mappingLocations的 value 会报上述错误

1、配置目录

<property name="mappingDirectoryLocations">
     <list>
      <!-- 用户hbm配置 -->
      <value>classpath:com/cuser/model</value>
      <!-- 学生hbm配置 -->
      <value>classpath:com/student/model</value>
     </list>
    </property>

 

2、配置文件
    <property name="mappingLocations">
     <list>
      <value>classpath:com/cuser/model/*.hbm.xml</value>
      <value>classpath:com/student/model/*.hbm.xml</value>
     </list>
    </property>


3、配置jar

     <property name="mappingJarLocations">
     <list>
      <value>WEB-INF/lib/jarName.jar</value>
     </list>
     </property>

欢迎加我的qq技术群425783133
    

### Java中文件或目录不存在导致的`IllegalArgumentException`异常解决方案 当尝试操作一个不存在的文件或目录时,可能会抛出`java.lang.IllegalArgumentException`异常。为了处理这种情况,应该先验证目标路径是否存在以及是否具有预期属性。 对于文件或目录的操作前应当做如下检查: - 使用`Files.exists()`方法来判断给定路径下的资源是否存在。 - 对于文件而言,还需确认其确实是一个文件而非其他类型的节点;可借助`Files.isRegularFile()`实现这一目的。 - 若目标为目录,则应通过`Files.isDirectory()`来进行校验。 下面给出一段示范代码用于安全创建新文件并写入内容,如果指定位置已经存在同名项则不会覆盖而是提示用户[^1]。 ```java import java.io.IOException; import java.nio.file.*; public class SafeFileCreator { public static void main(String[] args) throws IOException { Path path = Paths.get("example.txt"); try{ if (!Files.exists(path)) { // Check existence of the file. Files.createFile(path); // Create a new empty file at given location. System.out.println("Created " + path.toString()); // Writing content into newly created file. String textToWrite = "This is an example."; Files.write(path, textToWrite.getBytes(), StandardOpenOption.WRITE); } else { System.out.println("The specified file already exists."); } } catch (InvalidPathException e){ System.err.format("Invalid path format: %s%n", e.getMessage()); } } } ``` 针对目录的情况也类似,只不过需要调用不同的API函数如`Files.createDirectories()`来确保整个路径都被正确建立起来。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值