SSM 记录
Posted maoyan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SSM 记录相关的知识,希望对你有一定的参考价值。
前言:本过程从0开始,先是导入最核心的jar包,然后随着ssm中的功能实现,打包===>启动===>报错,一步步解决问题,增加额外的必须的jar包来熟悉ssm
1、导包(核心包)
mybatis:mybatis
msql:mysql-connector-java
spring:spring、spring-core、spring-web、spring-context、spring-beans
spring-mvc:spring-webmvc
mybatis-spring:mybatis-spring
2、配置文件
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: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"> <!-- 配置成拦截所有的请求,会有效@RequestMapper,如果是配置成*.do则无效 --> <mvc:annotation-driven /> <!-- 扫描指定包下含有特定注解的类 --> <context:component-scan base-package="com.test.*"/> <!-- 静态资源请求,启动容器的默认的handler来处理 --> <mvc:default-servlet-handler/> <!-- 试图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/" /> <property name="suffix" value=".jsp" /> </bean> </beans>
spring-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: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:property-placeholder location="/WEB-INF/classes/datasource.properties"/> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${driver}"/> <property name="username" value="${jdbc_username}"/> <property name="url" value="${url}"/> <property name="password" value="${pwd}"/> </bean> <!-- 数据库连接结束 --> </beans>
使用的context、mvc、tx、aop……标签时,需加上相应的协议
3、完善过程与问题记录
1)java.lang.NullPointerException
org.springframework.core.SerializableTypeWrapper$TypeProxyInvocationHandler.invoke(SerializableTypeWrapper.java:239)
<dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.5.3</version> <exclusions> <exclusion> <artifactId>spring</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency>
2)增加mybatis数据库操作,在spring-mybatis.xml增加配置
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:mapperAlias.xml" /> </bean> <!-- DAO接口所在包名,Spring会自动查找其下的类 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.test.dao" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean>
2.1)打包启动 错:java.lang.NoClassDefFoundError: org/springframework/dao/support/DaoSupport,增加spring-tx依赖
2.2)即上之后 打包启动 错误信息有java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy 增加spring-jdbc的依赖
2.3)单元测试 nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.csdn.training.service.BeanB] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. 原因是缺少bean的依赖注入。
参考:http://blog.csdn.net/jiangchao858/article/details/51586515
·
以上是关于SSM 记录的主要内容,如果未能解决你的问题,请参考以下文章