• springboot


    覆盖默认版本

    <properties>
        <spring-data-releasetrain.version>Fowler-SR2</spring-data-releasetrain.version>
    </properties>


    ***************************************
    @ContextConfiguration(locations = { "classpath*:/applicationContext.xml" })

    从属性文件中自动装配该类中
    @ConfigurationProperties(prefix = "spring.redis")
    public class RedisProperties {
        /**
         * Database index used by the connection factory.
         */
        private int database = 0;
    
        /**
         * Redis url, which will overrule host, port and password if set.
         */
        private String url;
    
        /**
         * Redis server host.
         */
        private String host = "localhost";
    
        /**
         * Login password of the redis server.
         */
        private String password;
    
        /**
         * Redis server port.
         */
        private int port = 6379;
        // 其它参数略
    }
    
    
    


    1 Application 会扫描同级包和下级包

    不过想自动配置第三方的插件
    @SpringBootApplication(exclude={RedisAutoConfiguration.class,})


    @PropertySource(value={"classpath:jdbc.properties",""})
    @PropertySource(value = "classpath:jdbc.properties",ignoreResourceNotFound = true)



    一、@PropertySource  加载外面资源文件

    @PropertySource(value={"person.properties"})
    @Configuration
    public class SpringConfigProperty {

        @Bean
        public Person person(){
            return new Person();
        }


    xml 加载外部资源方式

    <context:property-placeholder  location="classpath:spring-common.xml"/>

    二、@value 赋值的使用

    //使用@Value赋值;
    //1、基本数值
    //2、可以写SpEL; #{}
    //3、可以写${};取出配置文件【properties】中的值(在运行环境变量里面的值)
        @Value("1")
        private Integer id;
        @Value("${person.nickName}")
        private String name;
        @Value("#{20-2}")
        private String age;

    2 自定义banner.txt
    放到resource

    #配置程序端口,默认为8080
    server.port= 9000
    
    server.servlet.context-path=/tj
    #用户绘画session过期时间,以秒为单位
    
    
    # 配置Tomcat编码,默认为UTF-8
    server.tomcat.uri-encoding=UTF-8
    # 配置最大线程数
    server.tomcat.max-threads=1000
    
    
    # 默认值为 /**
    #例如改成/my/**,那运行的时候访问 http://lcoalhost:8080/dudu/my.html 才对应到index.html页面。
    #spring.mvc.static-path-pattern=/my/**
    spring.mvc.static-path-pattern=/**
    # 默认值为 classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
    spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/

    态资源存放的默认位置由4个目录,分别在根目录,即/src/main/resources/目录下的/META-INF/resources//resources//static//public/目录下(优先级也是这个顺序)。

    #热部署重启 static下的文件修改不重启 #spring.devtools.restart.exclude=static/**,public/** # jsp 开始---------------------- #spring.mvc.view.prefix=/WEB-INF/jsp/ #spring.mvc.view.suffix=.jsp # jsp 结束---------------------- # freemarker 开始---------------------- spring.freemarker.allow-request-override=false spring.freemarker.allow-session-override=false spring.freemarker.cache=true spring.freemarker.check-template-location=true spring.freemarker.content-type=text/html spring.freemarker.enabled=true spring.freemarker.expose-request-attributes=false spring.freemarker.expose-session-attributes=false spring.freemarker.expose-spring-macro-helpers=true spring.freemarker.prefer-file-system-access=true spring.freemarker.suffix=.ftl spring.freemarker.template-loader-path=classpath:/templates/ spring.freemarker.settings.template_update_delay=0 spring.freemarker.settings.default_encoding=UTF-8 spring.freemarker.settings.classic_compatible=true spring.freemarker.order=1 # freemarker 结束---------------------- ## REDIS (RedisProperties) #spring.redis.cluster.max-redirects= ## Maximum number of redirects to follow when executing commands across the cluster. #spring.redis.cluster.nodes= ## Comma-separated list of "host:port" pairs to bootstrap from. #spring.redis.database=0 ## Database index used by the connection factory. #spring.redis.url= ## Connection URL. Overrides host, port, and password. User is ignored. Example: redis://user:password@example.com:6379 #spring.redis.host=192.168.1.252 ## Redis server host. #spring.redis.jedis.pool.max-active=8 ## Maximum number of connections that can be allocated by the pool at a given time. Use a negative value for no limit. #spring.redis.jedis.pool.max-idle=8 ## Maximum number of "idle" connections in the pool. Use a negative value to indicate an unlimited number of idle connections. #spring.redis.jedis.pool.max-wait=-1ms ## Maximum amount of time a connection allocation should block before throwing an exception when the pool is exhausted. Use a negative value to block indefinitely. #spring.redis.jedis.pool.min-idle=0 ## Target for the minimum number of idle connections to maintain in the pool. This setting only has an effect if it is positive. #spring.redis.lettuce.pool.max-active=8 ## Maximum number of connections that can be allocated by the pool at a given time. Use a negative value for no limit. #spring.redis.lettuce.pool.max-idle=8 ## Maximum number of "idle" connections in the pool. Use a negative value to indicate an unlimited number of idle connections. #spring.redis.lettuce.pool.max-wait=-1ms ## Maximum amount of time a connection allocation should block before throwing an exception when the pool is exhausted. Use a negative value to block indefinitely. #spring.redis.lettuce.pool.min-idle=0 ## Target for the minimum number of idle connections to maintain in the pool. This setting only has an effect if it is positive. #spring.redis.lettuce.shutdown-timeout=100ms ## Shutdown timeout. #spring.redis.password=321 ## Login password of the redis server. #spring.redis.port=6379 ## Redis server port. #spring.redis.sentinel.master= ## Name of the Redis server. #spring.redis.sentinel.nodes= ## Comma-separated list of "host:port" pairs. #spring.redis.ssl=false ## Whether to enable SSL support. #spring.redis.timeout= ## Connection timeout.
    
    
    <?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.tj</groupId>
        <artifactId>tj-center</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>war</packaging>
    
        <name>tj-center</name>
        <description>Demo project for Spring Boot</description>
    
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.0.3.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-freemarker</artifactId>
            </dependency>
    
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-redis</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>io.lettuce</groupId>
                        <artifactId>lettuce-core</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>redis.clients</groupId>
                <artifactId>jedis</artifactId>
            </dependency>
    
    
            <!--代码发生改变自动重启CTRL+F9重新编译一下触发-->
            <!--devtools会自动帮你做到这些,禁用所有模板的缓存-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <optional>true</optional> <!-- 这个需要为 true 热部署才有效 -->
            </dependency>
    
    
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    
    </project>
    
    

    如果只是静态HTML页面,不带错误信息的,在resources/public/下面创建error目录,在error目录下面创建对应的状态码html即可 ,例如,要将404映射到静态HTML文件,您的文件夹结构如下所示:

    如果是动态模板页面,可以带上错误信息,在resources/templates/下面创建error目录,在error目录下面命名即可:

    如果同时存在静态页面500.html和动态模板的500.html,则后者覆盖前者。即templates/error/这个的优先级比resources/public/error高。

     
  • 相关阅读:
    IoC模式
    开发流程与模式
    YbSoftwareFactory
    简单的FTP文件安全识别方案
    C# 通过探测邮件服务器进行Email地址有效性检验
    YbRapidSolution for WinForm 插件生成项目总体架构介绍
    lucene.net已经从孵化器毕业
    XSql 源码开放
    TCP 套接字函数和入门级TCP编程
    C#中泛型学习笔记
  • 原文地址:https://www.cnblogs.com/jentary/p/9105708.html
Copyright © 2020-2023  润新知