问题原因为 mvc:annotation driven引错了约束
记录下,只需要在开始在初始化时读取springmvc的配置文件即可,不需要错综复杂的 *** 作
dispatcherServlet org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:application.xml dispatcherServlet / 然后Spring部分,搞个配置类,导入mybatis相关的组件
@ComponentScan(basePackages = "com.sifa") @Configuration public class MybatisAndResourceConfig{ @Bean("datasource") public DruidDataSource getDataSource(){ DruidDataSource dataSource=new DruidDataSource(); dataSource.setUrl("jdbc:mysql://localhost:3306/test?characterEncoding=utf8"); dataSource.setUsername("root"); dataSource.setPassword("123456"); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); return dataSource; } @Bean public SqlSessionFactoryBean getSqlSessionFactoryBean(DataSource dataSource){ SqlSessionFactoryBean sqlSessionFactoryBean=new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(dataSource); return sqlSessionFactoryBean; } @Bean public MapperScannerConfigurer getMapperScannerConfig(){ MapperScannerConfigurer mapperScannerConfigurer=new MapperScannerConfigurer(); mapperScannerConfigurer.setSqlSessionFactoryBeanName("getSqlSessionFactoryBean"); mapperScannerConfigurer.setbasePackage("com.sifa.dao"); return mapperScannerConfigurer; } @Bean public DataSourceTransactionManager getDataSourceTransactionManager(DataSource dataSource){ DataSourceTransactionManager dataSourceTransactionManager=new DataSourceTransactionManager(); dataSourceTransactionManager.setDataSource(dataSource); return dataSourceTransactionManager; } }欢迎分享,转载请注明来源:内存溢出
评论列表(0条)