简单来说,tomcat9启动失败的主要原因在applicationContext.xml文件中,以下是applicationContext.xml的全部内容(这是改正过之后的,已经可以成功启动tomcat服务器)。
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!--读取属性文件jdbc.properties classpath,部署到服务器上需要添加-->
<context:property-placeholder location="classpath:DzDataBase.properties"/>
<!--创建数据源-->
<bean id="myDataSources" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${user}"/>
<property name="password" value="${password}"/>
</bean>
<!--设置SqlSessionFactoryBean类-->
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<!--配置数据源-->
<property name="dataSource" ref="myDataSources"/>
<!--配置MyBatis的核心配置文件-->
<property name="configLocation" value="classpath:SqlMapConfig.xml"/>
<!--注册实体类的别名-->
<property name="typeAliasesPackage" value="com.ssm.pojo"/>
</bean>
<!--注册mapper.xml文件-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.ssm.mapper"/>
</bean>
</beans>
新手一枚,万万没想到,检查了一个下午的文件,之前写的纯springmvc老项目部署没有任何问题,到了ssm整合当中却发现,即便是相同的配置文件,但是ssm就是启动服务器失败。除开依赖相关的原因,失败主要是因为在引用本地核心配置文件时,没有在前面添上”classpath:”。
改正后:
读取属性文件: <context:property-placeholder location=”classpath:DzDataBase.properties”/>
读取MyBatis的核心配置文件:
<bean class=”org.mybatis.spring.SqlSessionFactoryBean”> <!–配置数据源–> <property name=”dataSource” ref=”myDataSources”/> <!–配置MyBatis的核心配置文件–> <property name=”configLocation” value=”classpath:SqlMapConfig.xml”/> <!–注册实体类的别名–> <property name=”typeAliasesPackage” value=”com.ssm.pojo”/> </bean>
版权声明:本文为m0_72755373原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。