01 | package com.mjh; |
02 |
03 | import org.apache.ibatis.session.SqlSessionFactory; |
04 | import org.apache.log4j.Logger; |
05 | import org.mybatis.spring.SqlSessionFactoryBean; |
06 | import org.mybatis.spring.annotation.MapperScan; |
07 | import org.springframework.boot.SpringApplication; |
08 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
09 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
10 | import org.springframework.boot.builder.SpringApplicationBuilder; |
11 | import org.springframework.boot.context.properties.ConfigurationProperties; |
12 | import org.springframework.boot.web.support.SpringBootServletInitializer; |
13 | import org.springframework.context.annotation.Bean; |
14 | import org.springframework.context.annotation.ComponentScan; |
15 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver; |
16 | import org.springframework.jdbc.datasource.DataSourceTransactionManager; |
17 | import org.springframework.transaction.PlatformTransactionManager; |
18 |
19 | import javax.sql.DataSource; |
20 |
21 | @EnableAutoConfiguration |
22 | @SpringBootApplication |
23 | @ComponentScan |
24 | @MapperScan ( "com.mjh.dao" ) |
25 | public 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日