前几天刚刚学了SSM框架整合今天被折腾了半天,查找了好多方法都无济于事。下面贴出代码:
Spring.xml
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.2.xsd 
http://www.springframework.org/schema/aop   
        http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  
        http://www.springframework.org/schema/security   
        http://www.springframework.org/schema/security/spring-security-3.2.xsd  
        http://www.springframework.org/schema/beans   
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
        http://www.springframework.org/schema/data/jpa   
        http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd  
        http://www.springframework.org/schema/tx   
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd  
        http://www.springframework.org/schema/context   
        http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <context:property-placeholder location="classpath:dbConfig.properties" /> <context:component-scan base-package="com.lph.forever.service"/></beans>spring-mybatis.xml
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.2.xsd 
http://www.springframework.org/schema/aop   
        http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  
        http://www.springframework.org/schema/security   
        http://www.springframework.org/schema/security/spring-security-3.2.xsd  
        http://www.springframework.org/schema/beans   
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
        http://www.springframework.org/schema/data/jpa   
        http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd  
        http://www.springframework.org/schema/tx   
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd  
        http://www.springframework.org/schema/context   
        http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<!-- 配置spring-mybatis整合文件 -->   

<!-- 配置数据源 -->
<bean
id="dataSource"
class="com.alibaba.druid.pool.DruidDataSource"
init-method="init"
destroy-method="close">

<!-- 基本属性 url、user、password -->
<property
name="driverClassName"
value="${driverClassName}" />
<property
name="url"
value="${jdbc.url}" />
<property
name="username"
value="${jdbc.username}" />
<property
name="password"
value="${jdbc.password}" /> <!-- 配置初始化大小、最小、最大 -->
<property
name="initialSize"
value="1" />
<property
name="minIdle"
value="1" />
<property
name="maxActive"
value="20" /> <!-- 配置获取连接等待超时的时间 -->
<property
name="maxWait"
value="60000" /> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property
name="timeBetweenEvictionRunsMillis"
value="60000" /> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property
name="minEvictableIdleTimeMillis"
value="300000" /> <property
name="validationQuery"
value="${validationQuery}" />
<property
name="testWhileIdle"
value="true" />
<property
name="testOnBorrow"
value="false" />
<property
name="testOnReturn"
value="false" /> <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
<property
name="poolPreparedStatements"
value="true" />
<property
name="maxPoolPreparedStatementPerConnectionSize"
value="20" /> <!-- 配置监控统计拦截的filters,去掉后监控界面sql无法统计 -->
<property
name="filters"
value="stat" />
</bean> <!-- 配置mybatis sqlSessionFactory -->
<bean
id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property
name="dataSource"
ref="dataSource" />
<property
name="mapperLocations"
value="classpath:com/lph/forever/mapper/*.xml" />
</bean> <!-- 配置Mapper.java (也就是dao) -->
<bean
id="mapperScannerConfigurer"
class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property
name="basePackage"
value="com.lph.forever.mapper" />
<property
name="sqlSessionFactoryBeanName"
value="sqlSessionFactory" />
</bean> <!-- 配置事务管理器 -->
<bean
id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property
name="dataSource"
ref="dataSource" />
</bean> <!-- 配置事务拦截器,什么方法自动拦截 -->
<tx:advice
id="transactionAdvice"
transaction-manager="transactionManager">
<tx:attributes>
<tx:method
name="add*"
propagation="REQUIRED" />
<tx:method
name="delete*"
propagation="REQUIRED" />
<tx:method
name="update*"
propagation="REQUIRED" />
<tx:method
name="find*"
propagation="SUPPORTS" />
</tx:attributes>
</tx:advice> <!-- 配置事务切入 -->
<aop:config >
<aop:pointcut
expression="execution(* com.lph.forever.service..*impl.*(..))"
id="transationPointcut" />
<aop:advisor
advice-ref="transactionAdvice"
pointcut-ref="transationPointcut" />
</aop:config> <!-- 配置druid监控JDBC -->
<bean
id="druid-stat-interceptor"
class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor" />
<bean
id="druid-stat-pointcut"
class="org.springframework.aop.support.JdkRegexpMethodPointcut">
<property name="patterns">
<list>
<value>com.lph.forever.service.*</value>
</list>
</property>
</bean>
<aop:config>
<aop:advisor
advice-ref="druid-stat-interceptor"
pointcut-ref="druid-stat-pointcut" />
</aop:config>
</beans>

Spring-mvc.xml
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.2.xsd 
http://www.springframework.org/schema/aop   
        http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  
        http://www.springframework.org/schema/security   
        http://www.springframework.org/schema/security/spring-security-3.2.xsd  
        http://www.springframework.org/schema/beans   
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
        http://www.springframework.org/schema/data/jpa   
        http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd  
        http://www.springframework.org/schema/tx   
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd  
        http://www.springframework.org/schema/context   
        http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <!-- 自动装配controller包下的handler -->
<context:component-scan base-package="com.lph.forever.controller" /> <!-- 采用注解方式配置 -->
<context:annotation-config /> <!-- 配置mvc注解驱动器 -->
<mvc:annotation-driven /> <!-- 配置mvc视图处理器,默认使用jstl,所以需要jstl包 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 配置视图解析器前缀 -->
<property
name="prefix"
value="/forever/" />
<!-- 配置视图解析器后缀 -->
<property
name="suffix"
value=".jsp" />
</bean></beans>
dbConfig.properties
driverClassName=com.mysql.cj.jdbc.Driver
validationQuery=SELECT 'x'
jdbc.url=jdbc:mysql:///forever?serverTimezone=GMT&useUnicode=true&characterEncoding=UTF-8
jdbc.username=root
jdbc.password=123456
UserMapper.java
package com.lph.forever.mapper;import com.lph.forever.po.User;public interface UserMapper {
    int deleteByPrimaryKey(Integer userid);    int insert(User record);    int insertSelective(User record);    User selectByPrimaryKey(Integer userid);    int updateByPrimaryKeySelective(User record);    int updateByPrimaryKey(User record);
}
UserService.java
package com.lph.forever.service;import com.lph.forever.po.User;public interface UserService {
public User findUserById(int userId);
}UserServiceImpl.java
package com.lph.forever.service.impl;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import com.lph.forever.mapper.UserMapper;
import com.lph.forever.po.User;
import com.lph.forever.service.UserService;@Service("userService")
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;

@Override
public User findUserById(int userId) {
// TODO Auto-generated method stub
return userMapper.selectByPrimaryKey(userId);
}
}

解决方案 »

  1.   

    FindUserController.java
    package com.lph.forever.controller;import javax.annotation.Resource;import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.servlet.ModelAndView;import com.lph.forever.po.User;
    import com.lph.forever.service.UserService;
    @Controller
    public class FindUserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/findUserById")
    public String findUserById() throws Exception {
    System.out.println();
    return "findUser";
    }
    }WEB.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                          http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    version="3.1"
    metadata-complete="true">
    <display-name>Forever</display-name> <!-- 加载spring容器 -->
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/classes/spring-*.xml,WEB-INF/classes/spring.xml</param-value>
    </context-param>

    <!-- spring监听器   -->
    <listener>
    <listener-class>org.springframework.web.context.ContextCleanupListener</listener-class>
    </listener> <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:spring-mvc.xml</param-value>
    </init-param>
    </servlet>

    <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>*.action</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    </web-app>
      

  2.   

    经过Junit测试可以通过正常使用,但是部署到tomcat之后报异常了。下面是异常信息:
    十一月 06, 2017 2:38:19 下午 org.apache.catalina.core.ApplicationContext log
    严重: StandardWrapper.Throwable
    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'findUserController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.lph.forever.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:581)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:367)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1340)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:756)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:676)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:642)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:690)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:558)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:499)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:172)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1183)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:779)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:133)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
    Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.lph.forever.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1502)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1099)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1060)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:578)
    ... 38 more十一月 06, 2017 2:38:19 下午 org.apache.catalina.core.StandardWrapperValve invoke
    严重: Allocate exception for servlet [springmvc]
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.lph.forever.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1502)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1099)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1060)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:578)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:367)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1340)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:756)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:676)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:642)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:690)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:558)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:499)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:172)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
      

  3.   

    经过一个早上的查找大概知道了是service注入失败的问题但是在论坛上面找了好多个方法都没有找到解决方法,也看到了好多和我一样的问题,最后也没有贴出解决方案。希望论坛大牛能给刚学习两天的小弟一点点的解决方法。
      

  4.   

    你将spring.xml里的<context:component-scan base-package="com.lph.forever.service"/>改为<context:component-scan base-package="com.lph.forever.service.*"/>试下
      

  5.   

    没有扫描到service,检查一下web中配置中<init-param>的spring-mvc.xml的大小写与你的文件名是否一致。你贴上来的一个大写一个小写
      

  6.   

    顺便检查下spring.xml的,如果都没问题再找找其他的
      

  7.   

     <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>WEB-INF/classes/spring-*.xml,WEB-INF/classes/spring.xml</param-value>
        </context-param>
    这改成
    <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-mybatis.xml,spring.xml</param-value>
        </context-param>
    在这里不能扫描mvc的配置文件
      

  8.   

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring.xml</param-value>
    </context-param>
    将spring-mybatis.xml 写在 spring.中,比较清晰。<import resource="spring-mybatis.xml" /> 
      

  9.   

    web.xml修改为:<?xml version="1.0" encoding="UTF-8"?>
    <web-app
        xmlns="http://xmlns.jcp.org/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                          http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
        version="3.1"
        metadata-complete="true">
        <display-name>Forever</display-name>
     
        <!-- 加载spring容器 -->
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>WEB-INF/classes/spring.xml</param-value>
        </context-param>
         
        <!-- spring监听器      -->
        <listener>
            <listener-class>org.springframework.web.context.ContextCleanupListener</listener-class>
        </listener>
     
        <servlet>
            <servlet-name>springmvc</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>springmvc</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    </web-app>
    spring-mvc.xml修改为:
    <beans
        xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:jpa="http://www.springframework.org/schema/data/jpa"
        xmlns:security="http://www.springframework.org/schema/security"
        xsi:schemaLocation="http://www.springframework.org/schema/mvc 
            http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.2.xsd 
            http://www.springframework.org/schema/aop   
            http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  
            http://www.springframework.org/schema/security   
            http://www.springframework.org/schema/security/spring-security-3.2.xsd  
            http://www.springframework.org/schema/beans   
            http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
            http://www.springframework.org/schema/data/jpa   
            http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd  
            http://www.springframework.org/schema/tx   
            http://www.springframework.org/schema/tx/spring-tx-4.0.xsd  
            http://www.springframework.org/schema/context   
            http://www.springframework.org/schema/context/spring-context-4.0.xsd">
     
        <context:property-placeholder location="classpath:dbConfig.properties" />
        
        <context:component-scan base-package="com.lph.forever.service"/>
        
      <import resource="spring-mvc.xml"/>
     
    </beans>
      

  10.   

    你的注解扫描 扫描不到service吧