1。在MyEclipse里创建一个maven项目.File> New> maven项目:
勾选图中红色部分,然后点下一步击。
2。填写下图中红色部分然后点击完成。
3。此时一个maven项目已经生成,目录结构如下:
4。打开pom.xml在里面编辑如下内容:
& lt;项目xmlns=" http://maven.apache.org/POM/4.0.0 " xmlns: xsi=" http://www.w3.org/2001/XMLSchema-instance " xsi: schemaLocation=" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”比; & lt; modelVersion> 4.0.0 & lt; groupId> com.lm.spring-boot & lt; artifactId> spring-boot & lt; version> 0.0.1-SNAPSHOT & lt; properties> & lt; project.build.sourceEncoding> UTF-8 & lt;/properties> & lt; parent> & lt; groupId> org.springframework.boot & lt; artifactId> spring-boot-starter-parent & lt; version> 1.3.0.RELEASE & lt;/parent> & lt; dependencies> & lt; dependency> & lt; groupId> org.springframework.boot & lt; artifactId> spring-boot-starter-web & lt;/dependency> & lt; !——视图采用freemarker渲染——比; & lt; dependency> & lt; groupId> org.springframework.boot & lt; artifactId> spring-boot-starter-freemarker & lt;/dependency> & lt; !- JDBC -比; & lt; dependency> & lt; groupId> org.springframework.boot & lt; artifactId> spring-boot-starter-jdbc & lt;/dependency> & lt; !——mybatis祝辞 & lt; dependency> & lt; groupId> org.mybatis & lt; artifactId> mybatis-spring & lt; version> 1.2.2 & lt;/dependency> & lt; dependency> & lt; groupId> org.mybatis & lt; artifactId> mybatis & lt; version> 3.2.8 & lt;/dependency> & lt; !——mysql——比; & lt; dependency> & lt; groupId> mysql & lt; artifactId> mysql-connector-java & lt;/dependency> & lt;/dependencies> & lt; build> & lt; plugins> & lt; plugin> & lt; artifactId> maven-compiler-plugin & lt; configuration> & lt; source> 1.6 & lt;/source> & lt; target> 1.6 & lt;/target> & lt;/configuration> & lt;/plugin> & lt; plugin> & lt; groupId> org.springframework.boot & lt; artifactId> spring-boot-maven-plugin & lt; executions> & lt; execution> & lt; goals> & lt; goal> repackage & lt;/goals> & lt;/execution> & lt;/executions> & lt; dependencies> & lt; dependency> & lt; groupId> org.springframework & lt; artifactId> springloaded & lt; version> 1.2.5.RELEASE & lt;/dependency> & lt;/dependencies> & lt;/plugin> & lt;/plugins> & lt; !——指定最终生成jar包的文件名——比; & lt; finalName> spring-boot & lt;/build> & lt;/project> >之前5。创建程序入口Application.java。
包com.lm.application; 进口org.apache.ibatis.session.SqlSessionFactory; 进口org.apache.tomcat.jdbc.pool.DataSource; 进口org.mybatis.spring.SqlSessionFactoryBean; 进口org.mybatis.spring.annotation.MapperScan; 进口org.springframework.boot.SpringApplication; 进口org.springframework.boot.autoconfigure.EnableAutoConfiguration; 进口org.springframework.boot.autoconfigure.SpringBootApplication; 进口org.springframework.boot.context.properties.ConfigurationProperties; 进口org.springframework.context.annotation.Bean; 进口org.springframework.context.annotation.ComponentScan; 进口org.springframework.core.io.support.PathMatchingResourcePatternResolver; 进口org.springframework.jdbc.datasource.DataSourceTransactionManager; 进口org.springframework.transaction.PlatformTransactionManager; @EnableAutoConfiguration @SpringBootApplication @ComponentScan (basePackages={" com.lm "})//指定弹簧管理的bean所在的包 @MapperScan (com.lm.dao)//指定mybatis的mapper接口所在的包 公共类应用程序{ 公共静态void main (String [] args) { SpringApplication.run (Application.class, args); }//创建数据源 @ bean @ConfigurationProperties(前缀=皊pring.datasource”)//指定数据源的前缀,在application.properties文件中指定 公共数据源的数据源(){ 返回新数据源(); }//创建SqlSessionFactory @ bean 公共SqlSessionFactory sqlSessionFactoryBean()抛出异常{ SqlSessionFactoryBean SqlSessionFactoryBean=new SqlSessionFactoryBean (); sqlSessionFactoryBean.setDataSource(数据源()); PathMatchingResourcePatternResolver解析器=new PathMatchingResourcePatternResolver (); sqlSessionFactoryBean.setMapperLocations (resolver.getResources(“类路径:/mybatis/* . xml”)); 返回sqlSessionFactoryBean.getObject (); }//创建事物管理器 @ bean null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null详解MyEclipse中搭建spring-boot + mybatis + freemarker框架