文档根元素 "beans" 必须匹配 DOCTYPE 根 "null"。
项目已经基本完工了,本是打算起来运行测试一番,然后就开始报各种错,前面的就先不说了 ,都很离奇,因为项目之前测试是好用的,不知为何。
定位的错误应该是发生在spring配置文件,最后这个错在网上找了好多的博客解决办法,但是都不行。(配置文件配好之后都没动过,之前也是正常运行的)
找了很多,最后我的解决办法是把这个spring文件删掉,重新写了一份,然后项目就起来了。。。。重新构建项目,不要用maven重新构建,自己也是刚接触maven不太懂,但是自己的感觉maven重新构建会出一些问题(个人看法),然后我试着用这个,如图:
在附一下之前的配置文件:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:redis="http://www.springframework.org/schema/redis"
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/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/redis
http://www.springframework.org/schema/redis/spring-redis-1.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!--注解开发 扫描包产生对象-->
<context:component-scan base-package="com.shop"/>
<!--加载连接池属性文件-->
<context:property-placeholder location="classpath:db.properties"/>
<context:property-placeholder
location="classpath:redis.properties" file-encoding="UTF-8"
ignore-unresolvable="true" ignore-resource-not-found="true" order="2"
system-properties-mode="NEVER" />
<!--配置c3p0连接池-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${db.driver}"/>
<property name="jdbcUrl" value="${db.url}"/>
<property name="user" value="${db.username}"/>
<property name="password" value="${db.password}"/>
<property name="maxPoolSize" value="${c3p0.maxPoolSize}"/>
<property name="minPoolSize" value="${c3p0.minPoolSize}"/>
<property name="autoCommitOnClose" value="${c3p0.autoCommitOnClose}"/>
<property name="checkoutTimeout" value="${c3p0.checkoutTimeout}"/>
<property name="acquireRetryAttempts" value="${c3p0.acquireRetryAttempts}"/>
</bean>
<!--配置sqlsessionFactory 产生sqlsession对象-->
<bean id="factoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="com.shop.pojo"/>
<!-- 扫描sql配置文件:mapper需要的xml文件 -->
<property name="mapperLocations" value="classpath:applicationContext.xml"/>
<property name="configLocation" value="classpath:sqlMapConfig.xml"/>
</bean>
<bean id="keySerializer"
class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
<bean id="valueSerializer"
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="200"/>
<property name="maxIdle" value="50"/>
<property name="minIdle" value="8"/>
<property name="maxWaitMillis" value="5000"/>
<property name="numTestsPerEvictionRun" value="10"/>
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="30000"/>
<property name="minEvictableIdleTimeMillis" value="60000"/>
</bean>
<bean id="jedisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="poolConfig" ref="jedisPoolConfig"/>
<property name="hostName" value="localhost" />
<property name="port" value="6379"/>
<property name="password" value=""/>
<property name="database" value="11"/>
<property name="timeout" value="1800"/>
<property name="usePool" value="true"/>
</bean>
<!-- redis template definition -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory"/>
<property name="keySerializer" ref="keySerializer"/>
<property name="valueSerializer" ref="valueSerializer"/>
<property name="hashKeySerializer" ref="keySerializer"/>
<property name="hashValueSerializer" ref="valueSerializer"/>
<property name="enableTransactionSupport" value="false"/>
</bean>
<bean id="redisTemplateTransactional" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory"/>
<property name="keySerializer" ref="keySerializer"/>
<property name="valueSerializer" ref="valueSerializer"/>
<property name="hashKeySerializer" ref="keySerializer"/>
<property name="hashValueSerializer" ref="valueSerializer"/>
<property name="enableTransactionSupport" value="true"/>
</bean>
<!--<bean id="redisHttpSessionConfiguration"
class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
<property name="maxInactiveIntervalInSeconds" value="1800"/>
<property name="cookieSerializer" ref="defaultCookieSerializer"/>
</bean>
<bean id="defaultCookieSerializer"
class="org.springframework.session.web.http.DefaultCookieSerializer">
</bean>-->
<!--配置dao对象 批量扫描获取-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--注入sqlsession-->
<property name="sqlSessionFactoryBeanName" value="factoryBean"/>
<!--指明要扫描的包-->
<property name="basePackage" value="com.shop.mapper"/>
</bean>
<!--事务-->
<!--配置事务管理器-->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!--配置事务详情-->
<tx:advice id="myAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<!--aop-->
<aop:config>
<aop:advisor advice-ref="myAdvice" pointcut="execution(* com.shop.service.*.*(..) )"/>
</aop:config>
</beans>
在附一下起动成功后的配置文件:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!--注解开发,扫描要产生对象的包-->
<context:component-scan base-package="com.shop"/>
<!--加载连接池属性文件-->
<context:property-placeholder location="classpath:db.properties"/>
<context:property-placeholder
location="classpath:redis.properties" file-encoding="UTF-8"
ignore-unresolvable="true" ignore-resource-not-found="true" order="2"
system-properties-mode="NEVER" />
<!--配置c3p0连接池-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${db.driver}"/>
<property name="jdbcUrl" value="${db.url}"/>
<property name="user" value="${db.username}"/>
<property name="password" value="${db.password}"/>
<property name="maxPoolSize" value="${c3p0.maxPoolSize}"/>
<property name="minPoolSize" value="${c3p0.minPoolSize}"/>
<property name="autoCommitOnClose" value="${c3p0.autoCommitOnClose}"/>
<property name="checkoutTimeout" value="${c3p0.checkoutTimeout}"/>
<property name="acquireRetryAttempts" value="${c3p0.acquireRetryAttempts}"/>
</bean>
<!--配置sqlSessionFacyory 产生sqlSesson对象-->
<bean id="factoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="typeAliasesPackage" value="com.shop.pojo"/>
<!--扫描sql配置文件,mapper需要的xml文件-->
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
<property name="configLocation" value="classpath:sqlMapConfig.xml"/>
</bean>
<bean id="keySerializer"
class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
<bean id="valueSerializer"
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="200"/>
<property name="maxIdle" value="50"/>
<property name="minIdle" value="8"/>
<property name="maxWaitMillis" value="5000"/>
<property name="numTestsPerEvictionRun" value="10"/>
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="30000"/>
<property name="minEvictableIdleTimeMillis" value="60000"/>
</bean>
<bean id="jedisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="poolConfig" ref="jedisPoolConfig"/>
<property name="hostName" value="localhost" />
<property name="port" value="6379"/>
<property name="password" value=""/>
<property name="database" value="11"/>
<property name="timeout" value="1800"/>
<property name="usePool" value="true"/>
</bean>
<!-- redis template definition -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory"/>
<property name="keySerializer" ref="keySerializer"/>
<property name="valueSerializer" ref="valueSerializer"/>
<property name="hashKeySerializer" ref="keySerializer"/>
<property name="hashValueSerializer" ref="valueSerializer"/>
<property name="enableTransactionSupport" value="false"/>
</bean>
<bean id="redisTemplateTransactional" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory"/>
<property name="keySerializer" ref="keySerializer"/>
<property name="valueSerializer" ref="valueSerializer"/>
<property name="hashKeySerializer" ref="keySerializer"/>
<property name="hashValueSerializer" ref="valueSerializer"/>
<property name="enableTransactionSupport" value="true"/>
</bean>
<!--配置dao对象 批量扫描获取-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--注入sqlsession-->
<property name="sqlSessionFactoryBeanName" value="factoryBean"/>
<!--指明要扫描的包-->
<property name="basePackage" value="com.shop.mapper"/>
</bean>
<!--事务-->
<!--配置事务管理器-->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!--配置事务详情-->
<tx:advice id="myAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<!--aop-->
<aop:config>
<aop:advisor advice-ref="myAdvice" pointcut="execution(* com.shop.service.*.*(..))"/>
</aop:config>
</beans>
只不过是上面多了个没用的redis的约束,没关系的,测试了不是它的问题。自己也是一头雾水,为什么突然不好使了,问题为什么出现在spring配置文件中,然后这个配置文件我也没查出来哪的问题。重写一遍就好了,希望有懂得大神可以分享下经验。
有和我遇见同样问题得可以试试删掉spring,重新写一遍。