springmvc @servicebean注入失败,求大神解决啊,欲哭如泪了

huanglihua123 2018-01-15

web.xml

<?xml version="1.0" encoding="UTF-8"?>  

<web-app version="3.0"  

    xmlns="http://java.sun.com/xml/ns/javaee"  

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  

    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  

    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

    

    <!-- 配置 Spring -->

    <listener>

        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

    </listener>

    <context-param>

        <param-name>contextConfigLocation</param-name>

        <param-value>classpath:config/spring.xml</param-value>

    </context-param>

    <!-- 防止Spring内存溢出监听器 -->

    <listener>

        <listener-class>org.springframework.web.util.IntrospectorCleanupListener</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:config/spring-mvc.xml</param-value>

        </init-param>

        <load-on-startup>1</load-on-startup>

        <async-supported>true</async-supported>

    </servlet>

    <servlet-mapping>

        <servlet-name>springMVC</servlet-name>

        <url-pattern>/</url-pattern>

    </servlet-mapping>

     

    <!-- 字符集过滤器 -->

    <filter>

        <filter-name>encodingFilter</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>

        <init-param>

            <param-name>forceEncoding</param-name>

            <param-value>true</param-value>

        </init-param>

    </filter>

    <filter-mapping>

        <filter-name>encodingFilter</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>

    

    <!-- 4、使用Rest风格的URI,将页面普陀的post请求 转为指定的delete或者put请求 -->  

    <filter>  

        <filter-name>HiddenHttpMethodFilter</filter-name>  

        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>  

    </filter>  

    <filter-mapping>  

        <filter-name>HiddenHttpMethodFilter</filter-name>  

        <url-pattern>/*</url-pattern>  

    </filter-mapping>  

  

    <!-- 配置过滤器:要求支持直接发送PUT之类的请求还要封装请求体的数据 。 AJAX发送请求方式为PUT时,tomcat不会封装请求体的数据为map,只有POST形式请求才封装到请求体。 -->  

    <filter>  

        <filter-name>HttpPutFormContentFilter</filter-name>  

        <filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class>  

    </filter>  

    <filter-mapping>  

        <filter-name>HttpPutFormContentFilter</filter-name>  

        <url-pattern>/*</url-pattern>  

    </filter-mapping> 

    <!-- 错误跳转页面 -->  

    <error-page>  

        <!-- 路径不正确 -->  

        <error-code>404</error-code>  

        <location>/WEB-INF/page/error/404.jsp</location>  

    </error-page>  

    <error-page>  

        <!-- 没有访问权限,访问被禁止 -->  

        <error-code>405</error-code>  

        <location>/WEB-INF/page/error/405.jsp</location>  

    </error-page>  

    <error-page>  

        <!-- 内部错误 -->  

        <error-code>500</error-code>  

        <location>/WEB-INF/page/error/500.jsp</location>  

    </error-page>    

    

    <!-- 登录认证过滤器 

     <filter>

         <filter-name>auth</filter-name>

         <filter-class>com.zxh.wesys.base.filter.AuthFilter</filter-class>

     </filter>

     <filter-mapping>

         <filter-name>auth</filter-name>

         <url-pattern>*.jsp</url-pattern>

     </filter-mapping>

     <filter-mapping>

         <filter-name>auth</filter-name>

         <url-pattern>*.html</url-pattern>

     </filter-mapping>

     <filter-mapping>

         <filter-name>auth</filter-name>

         <url-pattern>*.do</url-pattern>

     </filter-mapping>-->

</web-app>

 

spring.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: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"  

    xsi:schemaLocation="http://www.springframework.org/schema/beans   

            http://www.springframework.org/schema/beans/spring-beans.xsd   

            http://www.springframework.org/schema/mvc   

            http://www.springframework.org/schema/mvc/spring-mvc.xsd   

            http://www.springframework.org/schema/context   

            http://www.springframework.org/schema/context/spring-context.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 ">

  

    <!-- 扫描service、dao组件  

    <context:component-scan base-package="com.zxh.wesys" use-default-filters="false" /> -->

    <context:component-scan base-package="com.zxh.wesys.*" use-default-filters="false">  

        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />  

    </context:component-scan>

    <!-- 分解配置 jdbc.properites -->  

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

      

    <!-- 数据源c3p0 -->  

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">  

        <property name="driverClass" value="${jdbc.driverClassName}" />  

        <property name="jdbcUrl" value="${jdbc.url}" />  

        <property name="user" value="${jdbc.username}" />  

        <property name="password" value="${jdbc.password}" />  

        <property name="maxPoolSize" value="${c3p0.pool.size.max}" />  

        <property name="minPoolSize" value="${c3p0.pool.size.min}" />  

        <property name="initialPoolSize" value="${c3p0.pool.size.ini}" />  

        <property name="acquireIncrement" value="${c3p0.pool.size.increment}" />  

    </bean>  

  

  

    <!-- sessionFactory 将spring和mybatis整合 -->  

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  

        <property name="dataSource" ref="dataSource" />  

        <property name="configLocation" value="classpath:config/spring-mybatis.xml" />  

        <property name="mapperLocations" value="classpath:com/zxh/wesys/mapping/**/*.xml" />  

    </bean>  

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  

        <property name="basePackage" value="com.zxh.wesys.dao" />  

        <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="append*" propagation="REQUIRED" />  

            <tx:method name="insert*" propagation="REQUIRED" />  

            <tx:method name="save*" propagation="REQUIRED" />  

            <tx:method name="update*" propagation="REQUIRED" />  

            <tx:method name="modify*" propagation="REQUIRED" />  

            <tx:method name="edit*" propagation="REQUIRED" />  

            <tx:method name="delete*" propagation="REQUIRED" />  

            <tx:method name="remove*" propagation="REQUIRED" />  

            <tx:method name="repair" propagation="REQUIRED" />  

            <tx:method name="delAndRepair" propagation="REQUIRED" />  

  

            <tx:method name="get*" propagation="SUPPORTS" />

            <tx:method name="find*" propagation="SUPPORTS" />

            <tx:method name="load*" propagation="SUPPORTS" />

            <tx:method name="search*" propagation="SUPPORTS" />

            <tx:method name="datagrid*" propagation="SUPPORTS" />

  

            <tx:method name="*" propagation="SUPPORTS" />

        </tx:attributes>

    </tx:advice>

    <aop:config>

        <aop:pointcut id="transactionPointcut" expression="execution(* com.zxh.wesys.service..*Impl.*(..))" />

        <aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" />

    </aop:config> -->

</beans>

 

spring-mvc.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:p="http://www.springframework.org/schema/p"  

    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">  

    

    <!-- 默认的注解映射的支持 <mvc:default-servlet-handler/>  -->

    <mvc:annotation-driven />

    

    <!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器    

    <context:component-scan base-package="com.zxh.wesys.controller" />-->

    <context:component-scan base-package="com.zxh.wesys.*" use-default-filters="false">  

        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />  

    </context:component-scan>  

  

    <!--避免IE执行AJAX时,返回JSON出现下载文件  

    <bean id="mappingJacksonHttpMessageConverter"  

        class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">  

        <property name="supportedMediaTypes">  

            <list>  

                <value>text/html;charset=UTF-8</value>  

            </list>  

        </property>  

    </bean>   -->

    <!-- 完成请求和注解POJO的映射

    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

    <bean id="defaultAnnotationHandlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />

<bean id="annotationMethodHandlerAdapter" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> -->

 

    <!-- 定义跳转的文件的前后缀 ,视图模式配置 -->  

    <bean  

        class="org.springframework.web.servlet.view.InternalResourceViewResolver">  

        <!-- 这里的配置我的理解是自动给后面action的方法return的字符串加上前缀和后缀,变成一个 可用的url地址 -->  

        <property name="prefix" value="/WEB-INF/page/" />

        <property name="suffix" value=".html" />  

    </bean>  

  

    <!-- 配置文件上传,如果没有使用文件上传可以不用配置,当然如果不配,那么配置文件中也不必引入上传组件包 -->  

    <bean id="multipartResolver"  

        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  

        <!-- 默认编码 -->  

        <property name="defaultEncoding" value="utf-8" />  

        <!-- 文件大小最大值 -->  

        <property name="maxUploadSize" value="10485760000" />  

        <!-- 内存中的最大值 -->  

        <property name="maxInMemorySize" value="40960" />  

    </bean>  

    <!--配置拦截器, 多个拦截器,顺序执行 -->

    <mvc:interceptors>

    <mvc:interceptor>    

        <!-- 匹配的是url路径, 如果不配置或/**,将拦截所有的Controller -->  

        <mvc:mapping path="/**" />  

        <!--<mvc:exclude-mapping path="/interceptor/b" />不匹配的 -->

        <!--<mvc:mapping path="/user/**" />  -->

        <bean class="com.zxh.wesys.base.filter.LoginHandlerIntercepter"></bean>    

    </mvc:interceptor>  

    <!-- 当设置多个拦截器时,先按顺序调用preHandle方法,然后逆序调用每个拦截器的postHandle和afterCompletion方法 -->  

</mvc:interceptors> 

    

</beans> 

 

package com.zxh.wesys.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.zxh.wesys.service.UserService;

/**
 * @ClassName : UserServiceImpl。java
 * @Decription : 用户信息管理Service实现类
 * @Version : 2018/01/11  hlh  新建作成
 *
 */
@Controller
@RequestMapping("/userControl")
public class UserController {
	@Autowired
    private UserService userService;  
      
	/**
     * 根据查询条件,获取用户信息集合。
     * @param   condition  查询条件对象  
     * @return  用户信息集合
     */
    @RequestMapping(value="/getUserInfoList")   
    @ResponseBody  
    private ModelAndView  getUserInfoList() {
    	String me = "Hello World, Spring 3.0!";  
    	ModelAndView modelAndView = new ModelAndView();  
    	modelAndView.addObject("message", me);  
    	modelAndView.setViewName("login/login");  
    	return modelAndView;  
    	  
//    	System.out.println("执行UserController");
//    	String json = "";
//    	User conditionUser = new User();
//    	List<User> queryUserList;
//    	queryUserList = userService.getUserInfoList(conditionUser);  
//        return queryUserList;  
    }  
}

 

package com.zxh.wesys.service.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zxh.wesys.dao.UserMapper;
import com.zxh.wesys.model.User;
import com.zxh.wesys.service.UserService;

/**
 * @ClassName : UserServiceImpl。java
 * @Decription : 用户信息管理Service实现类
 * @Version : 2018/01/11  hlh  新建作成
 *
 */
@Service("userService")
public class UserServiceImpl implements UserService {
	@Autowired
	private UserMapper userDao;
	/**
     * 根据查询条件,获取用户信息集合。
     * @param   condition  查询条件对象  
     * @return  用户信息集合
     */
    public List<User> getUserInfoList(User condition) {
    	List<User> userList = new ArrayList<User>();
    	userList = userDao.getUserInfoList(condition);
    	return userList;
    }
}

 

 

huanglihua123 2018-01-15
哪位朋友帮忙给看看,,,
Global site tag (gtag.js) - Google Analytics