002--SpringBoot的花式玩法

话题一:使用自定义Banner文字


话题二:不使用Banner文字

setBannerMode(Mode.OFF);

public static void main(String[] args) {
        SpringApplication application = new SpringApplication(HelloApplication.class);
        application.setBannerMode(Mode.OFF);
        application.run(args);
    }

话题三:修改SpringBoot的默认端口

  • 1.添加默认配置文件application.property或者application.yml
  • 2.添加配置更改(以application.yml为例)
server:
  port: 8088
  • 3.重启程序即可

话题四:修改DispatcherServlet的规则

默认是/,现在可以修改成/api/

server:
  port: 8088
  servlet-path: /api/*

话题五:引入xml文件

  • Properties文件:mongodb-context-config.properties
mongo.host=www.wenbronk.com
mongo.port=27017
mongo.connectionsPerHost=8
mongo.threadsAllowedToBlockForConnectionMultiplier=4
mongo.connectTimeout=1000
mongo.maxWaitTime=1500
mongo.autoConnectRetry=true
mongo.socketKeepAlive=true
mongo.socketTimeout=1500
mongo.slaveOk=true
mongo.writeNumber=1
mongo.riteTimeout=0
mongo.writeFsync=true
  • XML文件:mongodb-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
    http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
    <context:component-scan base-package="com.mongo" />
    <!-- 获取配置资源 -->
    <!-- <context:property-placeholder location="classpath:mongodb-context-config.properties" /> -->
    <context:property-placeholder location="classpath:mongodb-context-config.properties" ignore-unresolvable="true"/> 
    
    <mongo:mongo id="mongo" host="${mongo.host}" port="${mongo.port}" >
        <mongo:options 
            connections-per-host="${mongo.connectionsPerHost}" 
            threads-allowed-to-block-for-connection-multiplier="${mongo.threadsAllowedToBlockForConnectionMultiplier}" 
            connect-timeout="${mongo.connectTimeout}" 
            max-wait-time="${mongo.maxWaitTime}" 
            auto-connect-retry="${mongo.autoConnectRetry}" 
            socket-keep-alive="${mongo.socketKeepAlive}" 
            socket-timeout="${mongo.socketTimeout}" 
            slave-ok="${mongo.slaveOk}" 
            write-number="1" 
            write-timeout="0" write-fsync="true"/> 
    </mongo:mongo>
    <!-- 设置使用的数据库 名-->
    <mongo:db-factory dbname="test" mongo-ref="mongo"/>
    <!-- mongodb的模板 -->
    <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
       <constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
    </bean>
</beans>
  • Java文件:XMLSource.java
@Configuration
@ImportResource(locations={"classpath:mongodb/mongodb-context.xml"})
public class XMLSource {
 
}

话题六:Spring Boot application starters

  • 1.查询SpringBoot支持的starters
  • 2.官方文档
  • 3.搜索:Spring Boot application starters
    1096351-84cec5ea8bf58e34.png

话题七:Log日志

logging:
  level:
    org.springframework: DEBUG

话题八:其他相关的配置参考官方


话题九:SpringBoot注解大全

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值