SSM项目 运行tomcat 报错 HTTP Status 500 - Servlet.init() for servlet dispatcherServlet threw exception

文章描述了一位开发者在SSM项目中遇到的错误,源于applicationContext.xml中的db.properties路径配置错误,缺少了classpath前缀,导致Spring框架无法正确加载配置。
摘要由CSDN通过智能技术生成

这是我SSM项目报错。经过检查后,依赖,web.xml,mvc.xml ,来源于复制粘贴不存在错误。

错误根源在于 applicationContext.xml 文件

错误的 applicationContext.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.alibaba.com/schema/stat"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.alibaba.com/schema/stat http://www.alibaba.com/schema/stat.xsd">

    <context:component-scan base-package="zx.example"/>
    <context:property-placeholder location="db.properties"/>
    <bean class="com.alibaba.druid.pool.DruidDataSource" id="dataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>
    <bean class="org.mybatis.spring.SqlSessionFactoryBean" id="sqlSessionFactory">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="zx.example.mapper"/>
    </bean>

    <bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager">
        <property name="dataSource"  ref="dataSource" />
    </bean>
    <tx:annotation-driven/>
</beans>

 !!!原因在于 db.properties 文件的配置 

我写的(错误)

 <context:property-placeholder location="db.properties"/>

正确的 db.properties 文件配置

  <context:property-placeholder location="classpath:db.properties"/>

就因为缺少了这个 "classpath:" 的前缀,导致了这个报错

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值