启动SSM项目报BeanFactory not initialized or already closed - call 'refresh' before accessing beans...错误

大佬们来看看,实在找不出来了

BeanFactory not initialized or already closed - call ‘refresh’ before accessing beans via the ApplicationContext

配置文件

applicationContext.xml

// An highlighted block
<?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 
                           http://www.springframework.org/schema/context/spring-context.xsd"
       >

<context:component-scan base-package="com.bornsoft.mapper"></context:component-scan>
<context:component-scan base-package="com.bornsoft.service"></context:component-scan>
<context:property-placeholder location="classpath:jdbc.properties></context:property-placeholder>
<import resource="classpath:mybatis.xml"> </import>
</beans>

mybatis.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:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
       
     <!-- 配置数据源 -->
     <bean id="dataSources" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
         <property name="driverClassName" value="${jdbc.driverClassName}"></property>
         <property name="url" value="${jdbc.url}"></property>
         <property name="username" value="${jdbc.username}"></property>
         <property name="password" value="${jdbc.password}"></property>
         <!-- 最大链接数 -->
        <!--  <property name="maxActive" value="12"></property> -->
         <!-- 最大空闲数 -->
         <!-- <property name="maxIdle" value="3"></property> -->
         <!-- 最大等待时间 -->
         <!-- <property name="maxWait" value="15"></property> -->
     </bean>
     <!-- 配置Session工厂 -->
     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
     <property name="dataSource" ref="dataSources"></property>
     <!-- 给实体类起别名 -->
     <property name="typeAliasesPackage" value="com.bornsoft.model"></property>
     <property name="mapperLocations" value="classpath:com/bornsoft/mapper/*.xml">
     </property>
     </bean>
     <!-- 检查搜索mapper接口 -->  
     <bean id="scannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
         <property name="basePackage" value="com.bornsoft.mapper"></property>
     </bean>
     <!-- 加入事物 -->
     <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
     <property name="dataSource" ref="dataSources"></property>
     </bean>
     <!-- 增强事物(通知) -->
     <tx:advice id="interceptor" transaction-manager="transactionManager">
         
         <tx:attributes>
         <!--  事物的传播行为 -->
         <!--  PROPAGATION_REQUIRED如果没有事物如果当前没有事务,就新建一个事务,如果已经存在一个事务中,加入到这个事务中。 -->
         <tx:method name="add*" propagation="REQUIRED"/>
         <tx:method name="insert*" propagation="REQUIRED"/>
         <!-- PROPAGATION_SUPPORTS支持当前事务,如果当前没有事务,就以非事务方式执行。 -->
         <tx:method name="get*" propagation="SUPPORTS"/>
         <tx:method name="find*" propagation="SUPPORTS"/>
         <tx:method name="select*" propagation="SUPPORTS"/>
         </tx:attributes>
     </tx:advice>
     <aop:config>
       <aop:advisor advice-ref="interceptor" pointcut="execution(* com.bornsoft.service.*.*(..))"/>
     </aop:config>
 </beans>

SpringMVC.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:mvc="http://www.springframework.org/schema/mvc"
       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.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
   <!-- 扫描controller 加入到Springmvc中 -->
   <context:component-scan base-package="com.bornsoft.controller"></context:component-scan>
   <!-- 加载处理器适配器和处理器映射器 -->
   <mvc:annotation-driven/>
   <!-- 定义视图解析器 -->
   <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
        <property name="prefix" value="/"></property>
        <property name="suffix" value=".jsp"></property>
   </bean>
</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <display-name>SSM</display-name>
  <!-- 加载Spring容器 -->
  <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <!-- 字符编码过滤器 -->
  <filter>
     <filter-name>code</filter-name>
     <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
     <init-param>
          <param-name>encoding</param-name>
          <param-value>UTF-8</param-value>
     </init-param>
  </filter>
  <filter-mapping>
     <filter-name>code</filter-name>
     <url-pattern>/</url-pattern>
  </filter-mapping>
  <!-- Spring监听器 -->
  <listener>
   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <!-- 配置SpringMVC -->
  <servlet>
     <servlet-name>SpringMVC</servlet-name>
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
     <init-param>
         <param-name>contextConfigLocation</param-name>
         <param-value>classpath:springMVC.xml</param-value>
     </init-param>
     <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
       <servlet-name>SpringMVC</servlet-name>
       <url-pattern>*.action</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>getAll.action</welcome-file>
  </welcome-file-list>
</web-app>

百度也找了好久说是什么id重复了我看了没有

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值