首页>代码>Springboot+Mybatis+maven+layui开发简单的学习实例>/bootWebDemo/src/main/java/com/mjh/Application.java
01package com.mjh;
02 
03import org.apache.ibatis.session.SqlSessionFactory;
04import org.apache.log4j.Logger;
05import org.mybatis.spring.SqlSessionFactoryBean;
06import org.mybatis.spring.annotation.MapperScan;
07import org.springframework.boot.SpringApplication;
08import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
09import org.springframework.boot.autoconfigure.SpringBootApplication;
10import org.springframework.boot.builder.SpringApplicationBuilder;
11import org.springframework.boot.context.properties.ConfigurationProperties;
12import org.springframework.boot.web.support.SpringBootServletInitializer;
13import org.springframework.context.annotation.Bean;
14import org.springframework.context.annotation.ComponentScan;
15import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
16import org.springframework.jdbc.datasource.DataSourceTransactionManager;
17import org.springframework.transaction.PlatformTransactionManager;
18 
19import javax.sql.DataSource;
20 
21@EnableAutoConfiguration
22@SpringBootApplication
23@ComponentScan
24@MapperScan("com.mjh.dao")
25public class Application{
26    private static Logger logger = Logger.getLogger(Application.class);
27 
28    @Bean
29    @ConfigurationProperties(prefix="spring.datasource")
30    public DataSource dataSource() {
31        return new org.apache.tomcat.jdbc.pool.DataSource();
32    }
33 
34    @Bean
35    public SqlSessionFactory sqlSessionFactoryBean() throws Exception {
36 
37        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
38        sqlSessionFactoryBean.setDataSource(dataSource());
39 
40        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
41 
42        sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mapper/*.xml"));
43 
44        return sqlSessionFactoryBean.getObject();
45    }
46 
47    @Bean
48    public PlatformTransactionManager transactionManager() {
49        return new DataSourceTransactionManager(dataSource());
50    }
51 
52    /**
53     * Start
54     */
55    public static void main(String[] args) {
56        SpringApplication.run(Application.class, args);
57        logger.info("SpringBoot Start Success");
58    }
59 
60}
最近下载更多
dane168  LV8 2月25日
huasir2018  LV14 1月29日
f22m1a2b2  LV17 2024年5月31日
ma406805131  LV19 2024年5月11日
阿达asdw1  LV4 2023年7月1日
2858477460  LV5 2023年3月9日
lironggang  LV38 2023年2月23日
冰枫xjz8  LV31 2022年5月10日
lyws1986  LV17 2021年12月17日
9843637  LV9 2021年12月15日
最近浏览更多
dane168  LV8 2月25日
huasir2018  LV14 1月29日
srmess  LV4 2024年12月30日
xianyu091012  LV5 2024年12月27日
计科一班  LV7 2024年6月19日
f22m1a2b2  LV17 2024年5月31日
ma406805131  LV19 2024年5月11日
哪里的完整版  LV8 2023年12月15日
Demo1111  LV30 2023年12月8日
haotzy  LV3 2023年10月8日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友