Skip to content

2021

Initialize a Database Using Basic SQL Scripts

Spring Boot can automatically create the schema (DDL scripts) of your JDBC DataSource or R2DBC ConnectionFactory and initialize it (DML scripts). It loads SQL from the standard root classpath locations: schema.sql and data.sql, respectively. In addition, Spring Boot processes the schema-${platform}.sql and data-${platform}.sql files (if present), where platform is the value of spring.sql.init.platform. This allows you to switch to database-specific scripts if necessary. For example, you might choose to set it to the vendor name of the database (hsqldb, h2, oracle, mysql, postgresql, and so on). By default, SQL database initialization is only performed when using an embedded in-memory database. To always initialize an SQL database, irrespective of its type, set spring.sql.init.mode to always. Similarly, to disable initialization, set spring.sql.init.mode to never. By default, Spring Boot enables the fail-fast feature of its script-based database initializer. This means that, if the scripts cause exceptions, the application fails to start. You can tune that behavior by setting spring.sql.init.continue-on-error.

Configure Extra Python PIP Index in Windows

In some cases, it needs to configure an extra pip repository for the pip in windows, here are the instructions.

  1. In the path %appdata%, create a directory pip
  2. Create a file pip.ini in the above-created directory pip
  3. Edit the created file pip.ini with the following example content

    INI
    [global]
    index-url = <extra repo url>
    extra-index-url = https://pypi.python.org/simple/
    trusted-host =  <extra repo host>
    pypi.python.org
    

When to Use Abstract Class and Interface

How do we know when to use interface or abstract class?

Interface

Interface declares a set a methods of an object, a class need to implement the methods define in the interface, and it can implement multiple interface.

  • any field defined in the interface is public static final
  • no static method
  • starts from JDK 8, an interface can have default method
  • an interface also may not include any method just a marker

SELinux == Enforcing and Nginx returns 403 for static files

For those who has SELinux == Enforcing and Nginx returns 403 for static files :

  1. Enable SELinux httpd_can_network_connect feature

    sudo setsebool -P httpd_can_network_connect on 2. check SELinux enforce

    getenforce 3. If it is Enforcing -

    chcon -Rt httpd_sys_content_t /path/to/www