springboot配置多模块项目
来源:互联网 发布:淘宝足球竞猜 编辑:程序博客网 时间:2024/05/20 23:05
用idea构建多模块spring boot项目,步骤如下:
1.创建父项目,删除src,target目录,只保留pom.xml。
2.配置父模块pom。
<?xml version="1.0" encoding="UTF-8"?><project 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"> <modelVersion>4.0.0</modelVersion> <groupId>com.xxxx.xxxxx</groupId> <artifactId>parent</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.3.RELEASE</version> </parent> <modules> <module>model</module> <module>dao</module> <module>service</module> <module>controller</module> </modules> <!--依赖关系--> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.2.2</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.2.8</version> </dependency> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-jdbc</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> </dependencies> <!--设置maven仓库--> <repositories> <repository> <id>spring-releases</id> <url>https://repo.spring.io/libs-release</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>spring-releases</id> <url>https://repo.spring.io/libs-release</url> </pluginRepository> </pluginRepositories></project>
3.创建子模块
右键create module。
4.修改子模块配置,打成jar包,引入需要的依赖。
controller需要引入service和model包;service需要引入dao和model包;dao需要引入model包。
这不是绝对的,具体情况具体分析。
5.创建启动类
在controller包里面建立有@SpringBootApplication注解的类,@ComponentScan指明需要扫描的包。
@SpringBootApplication@ComponentScan("com.xxxx.xxxx.project")public class Application { public static void main(String[] args){ SpringApplication.run(Application.class, args); }}
6.配置Mybatis
在dao包的resources文件夹中建立application.properties文件,用于配置数据连接信息。
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/bendispring.datasource.username=rootspring.datasource.password=123456spring.datasource.driver-class-name=com.mysql.jdbc.Driver设置dao文件路径和对应的xml文件路径。
@Configurationpublic class MyBatisConfig { @Bean @ConfigurationProperties(prefix = "spring.datasource") public DataSource dataSource(){ return new org.apache.tomcat.jdbc.pool.DataSource(); } @Bean(name = "sqlSessionFactory") public SqlSessionFactory sqlSessionFactoryBean() throws Exception { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(dataSource()); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:mybatis/*.xml")); return sqlSessionFactoryBean.getObject(); }
@Configuration@MapperScan("com.xxxx.xxxx.project.dao.mapping")@AutoConfigureAfter(MyBatisConfig.class)public class MyBatisMapperScannerConfig { public MapperScannerConfigurer mapperScannerConfigurer(){ MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer(); mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory"); mapperScannerConfigurer.setBasePackage("com.xxxx.xxxx.project.dao.mapping"); return mapperScannerConfigurer; }}
至此运行启动类的主函数,项目就可以跑起来了,如果遇到问题,还需要具体分析。
阅读全文
1 0
- springboot配置多模块项目
- SpringBoot创建maven多模块项目(实战)
- springboot+gradle 构建多模块项目
- 使用Gradle构建多模块SpringBoot项目
- Idea使用Maven创建多模块SpringBoot项目问题记录
- SpringBoot项目取消数据库配置
- springboot多模块(modules)开发
- maven 配置多模块项目 pom modules
- Gradle构建多模块项目(整合Java SE 和 Springboot)
- SpringCloud零基础上手(二)——SpringBoot多模块maven项目
- SpringBoot 多模块项目(module)Service自动注入(@Autowired)
- SpringBoot 多文件配置.
- springboot 多profile配置
- springboot多环境配置
- sbt项目中多模块(多个子项目)配置
- springboot-maven快速配置并启动项目
- Springboot项目配置myBatis连接MySQL数据库
- SpringBoot 项目属性的配置和使用
- Feed Happy Fish
- 今日头条成功的核心技术秘诀是什么?深度解密个性化资讯推荐技术 本文作者:AI研习社2017-07-05 12:24 导语:从“内行”的角度解密个性化资讯推荐技术。 雷锋网按:本文系知名 IT 技术资
- 【致敬ImageNet】ResNet 6大变体:何恺明,孙剑,颜水成引领计算机视觉这两年
- 新学习CSS特性总结
- with 语句那点事
- springboot配置多模块项目
- 精简的大数运算
- 定义一个返回内存的函数
- redis for all I know
- 如果我不曾遗忘,希望你也一样坚持
- 如何成为架构师系列:前言
- Servlet实现文件下载
- vim模式下文件的编辑与管理
- mybatis-xml配置