以往我们用SSM构建Web项目,需要一些配置文件,例如web.xml,spring-*.xml等等,servlet3.0+版本提供了基于注解模式的Web项目构建方式,省去了配置文件。本文主要描述了基于注解方式的Web项目环境搭建。
既然去掉了配置文件,那么我们需要编写一些配置类,来代替配置文件,构建起基本的项目环境,下面是Web项目基本环境的搭建:
import java.io.IOException;
import javax.sql.DataSource;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import com.alibaba.druid.pool.DruidDataSource;
@Configuration
@PropertySourc

本文介绍了如何使用Servlet3.0+的注解模式搭建基于SSM的Web项目,省去传统配置文件。通过@Configuration注解创建配置类,加载properties文件,配置数据库连接、Mybatis和Spring的整合,以及数据持久层接口的自动扫描。同时,设置了Servlet环境,启用WebMvc,定义视图解析器和拦截器。通过实现WebApplicationInitializer接口确保配置类在服务器启动时加载,规定请求路径以.do结尾。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



