配置了spring-boot-starter-web的依赖后,会自动添加tomcat和spring mvc的依赖,那么spring boot 会对tomcat和spring mvc进行自动配置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> 使用eclipse运行mvn spring boot项目时
在当前项目目录下,在地址栏输入cmd,进入命令提示行,输入mvn clean install --> mvn spring-boot:run执行 使用idea运行时
点击导航栏的run,如果没有配置过的话,点击Run.. --> 左上角+号,在右侧选择项目目录
下次直接点击该运行即可 maven 跳过测试
mvn install -Dmaven.test.skip=true --------------------------------------------------------------------------------------------------------
- 2017-05-11 16:15:32.410 [main] INFO o.a.catalina.core.StandardService - Stopping service Tomcat
- 2017-05-11 16:15:32.457 [main] INFO o.s.b.a.l.AutoConfigurationReportLoggingInitializer -
- Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
- 2017-05-11 16:15:32.726 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter -
- ***************************
- APPLICATION FAILED TO START
- ***************************
- Description:
- Field xxxMapper in XXXX required a bean of type 'XXXMapper' that could not be found.
- Action:
- Consider defining a bean of type 'XXXMapper' in your configuration.
- Process finished with exit code 1
使用spring boot或Spring cloud配置mybatis,我用的是mybatis-generator插件自动生成实体和DAO层以及XML文件,最后启动时报了上面的错误,解决方法是在你的启动程序上加上这么一句:
@MapperScan("xxx.mapper")
public class Application { public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
在Application类的上面,也就是配置你的mapper的路径。 需要再maven中加入 mybatis的依赖