springboot个人博客系统---搭建项目环境(一)

来源:互联网 发布:办公软件高级是几级 编辑:程序博客网 时间:2024/06/05 18:59

一、我使用的是idea编辑器创建springboot项目:
使用的idea编辑器创建springboot项目

二、选择你要用到的组件打钩

三、创建完成后的项目目录结构:
这里写图片描述
定制Banner(网上看到的小玩意~):
我们在启动Spring Boot项目的时候,在控制台会默认输出一个启动图案,如下:
这里写图片描述
1.在src/main/resources下新建一个banner.txt文档
2.通过http://patorjk.com/software/taag网站生成需要的字符,将字符拷贝到步骤1所创建的txt文档中

四、对配置文件进行配置:
这只是我这暂时的配置,可以根据实际需要自行修改;
(如果你导入了spring-session组件那么配置文件就得加入spring.session.store-type=none,如下)

#设置需要加载的额外配置文件(application-jdbc.properties)spring.profiles.active=jdbc# serverserver.context-path=/xxblogserver.port=8082# thymeleaf startspring.thymeleaf.prefix=classpath:/templates/spring.thymeleaf.check-template-location=truespring.thymeleaf.suffix=.htmlspring.thymeleaf.encoding=UTF-8spring.thymeleaf.content-type=text/htmlspring.thymeleaf.mode=HTML5#开发时关闭缓存,不然没法看到实时页面spring.thymeleaf.cache=false# thymeleaf end# mybatismybatis.mapper-locations=classpath:/mapper/*.xmlmybatis.type-aliases-package=com.myblog.dao# sessionspring.session.store-type=none#pagehelperpagehelper.helperDialect=mysqlpagehelper.reasonable=truepagehelper.support-methods-arguments=truepagehelper.params=count=countSql

五、配置启动类:

@MapperScan("com.myblog.dao")@SpringBootApplication@EnableTransactionManagement// 开启注解事务管理,等同于xml配置文件中的 <tx:annotation-driven />/** * @author xxw * @date 2017.11.22 * 项目启动入口类 */public class XxblogApplication extends SpringBootServletInitializer {    //需要启动类继承自SpringBootServletInitializer并覆盖configure方法方可正常部署至常规tomcat下    //其主要能够起到web.xml的作用    @Override    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {        return builder.sources(this.getClass());    }    /**     * 根据配置文件创建数据源     */    @Bean(initMethod = "init", destroyMethod = "close")    @ConfigurationProperties(prefix = "spring.datasource")    public DataSource dataSource() {        return new DruidDataSource();    }    /**     * 创建事物管理器     */    @Bean    public PlatformTransactionManager transactionManager() {        return new DataSourceTransactionManager(dataSource());    }    @Bean    public SqlSessionFactory sqlSessionFactoryBean() throws Exception {        //加载mybatis配置文件与数据源注入到sqlSessionFactory,        //拿到sqlSessionFactory并注入到spring容器中        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();        sqlSessionFactoryBean.setDataSource(dataSource());        sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath*:/mapper/*Mapper.xml"));        return sqlSessionFactoryBean.getObject();    }    public static void main(String[] args) {        SpringApplication.run(XxblogApplication.class, args);    }}

注意!!!
如果启动类没有配置@MapperScan(“xxx.mapper”)注解,则会报如下错误(提示你找不到Mapper接口):

Description:A component required a bean of type 'xxx.xxx.XxxMapper' that could not be found.Action:Consider defining a bean of type 'xxx.xxx.XxxMapper' in your configuration.
阅读全文
1 0
原创粉丝点击