Skip to content

Instantly share code, notes, and snippets.

/**
* Resolves method arguments annotated with @{@link RequestParam}, arguments of
* type {@link MultipartFile} in conjunction with Spring's {@link MultipartResolver}
* abstraction, and arguments of type {@code javax.servlet.http.Part} in conjunction
* with Servlet 3.0 multipart requests. This resolver can also be created in default
* resolution mode in which simple types (int, long, etc.) not annotated with
* @{@link RequestParam} are also treated as request parameters with the
* parameter name derived from the argument name.
* <p>If the method parameter type is {@link Map}, the name specified in the
* annotation is used to resolve the request parameter String value. The value is
1. Inject Map using Value annotation and SpEL
values in application.properties:
value1=1000
value2=2000
code:
@Value("#{{KEY1: ${value1}, KEY2: ${value2}}}")
private Map<String, Integer> map = new HashMap<>();
@cherniag
cherniag / logback.xml
Created May 23, 2016 12:49
Configure logback to consume passed variables
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- pass JVM args: -Dlog.file.location=custom.log -Dlog.level.root=TRACE -->
<!-- or defaults will be used : 'application.log' and 'DEBUG' -->
<!-- DEFAULT VALUE SEPARATOR IS ':-' NOT ':' AS SPRING USED -->
<property name="log.file.location" value="${log.file.location:-application.log}" />
<property name="log.level.root" value="${log.level.root:-DEBUG}" />
<appender name="file" class="ch.qos.logback.core.FileAppender">
@cherniag
cherniag / CENTOS
Last active August 1, 2016 12:17
LINIX
1. Install rpm
sudo yum install name.rpm
2. Start stop service
sudo systemctl start service_name
sudo systemctl stop service_name
3.Install jdk
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u60-b27/jdk-8u60-linux-x64.rpm"
****************************************************************
//before
String dbName = "unknown";
if (mongoOperations instanceof MongoTemplate) {
DB db = ((MongoTemplate) mongoOperations).getDb();
if (db != null) {
dbName = db.getName() != null ? db.getName() : "unknown";
}
}
//after
@cherniag
cherniag / liquibase.txt
Last active June 7, 2016 09:32
liquibase gotchas
1. After running changeset changelog's file name is stored in table databasechangelog column filename.
During liquibase next run several filters check eligibilty for every changeset, one of them is ShouldRunChangeSetFilter
which checks:
idsAreEqual(changeSet, ranChangeSet)
&& authorsAreEqual(changeSet, ranChangeSet)
&& pathsAreEqual(changeSet, ranChangeSet)
so if path is different but content the same liquibase tries to run changeset anyway.
There is attribute to "hardcode" path and after that no matter what is the path to file.
Attribute is
logicalFilePath="upgrade/db-changelog.xml"
@cherniag
cherniag / gist:6ef989358a198727ba70bc8241ac9f23
Last active December 23, 2016 16:51
Spring property placeholders
ENTRY POINT TO GET ACTUAL VALUE FOR PLACEHOLDER!!!
org.springframework.core.env.PropertySourcesPropertyResolver#getPropertyAsRawString
order of property sources at context refresh:
adds new @PropertySource source
org.springframework.context.annotation.ConfigurationClassParser#addPropertySource
called from
org.springframework.context.annotation.ConfigurationClassParser#processPropertySource
@cherniag
cherniag / CustomNamespaceDetails.java
Last active October 17, 2024 12:07
Extend liquibase to support custom changes
package company.artifact.persistence.liquibase.parser;
import liquibase.parser.LiquibaseParser;
import liquibase.parser.NamespaceDetails;
import liquibase.parser.core.xml.XMLChangeLogSAXParser;
import liquibase.serializer.LiquibaseSerializer;
import liquibase.serializer.core.xml.XMLChangeLogSerializer;
public class CustomNamespaceDetails implements NamespaceDetails {
@cherniag
cherniag / liquibase mysql add index on text field
Created February 29, 2016 16:05
liquibase mysql add index on text field
An index for a MySQL CLOB column cannot be created with Liquibase createIndex at the moment,
since MySQL requires a length limit for this index, see http://dev.mysql.com/doc/refman/5.5/en/create-index.html
As a workaround, you can use the modifySql to 'fix' the sql generated like so:
<createIndex tableName="foo" indexName="i_foo">
<column name="myClobColumn"/>
</createIndex>
<modifySql dbms="mysql">
<replace replace="myClobColumn" with="myClobColumn(80)"/>
</modifySql>
@cherniag
cherniag / CustomizedArgumentParser
Last active December 1, 2024 10:04
CustomizedPredicateBuilderStrategy for RSQL JPA, processes defined custom RSQL operator (=containsPair= in this case) and transforms to JPQL predicate to query by map's key and value
import com.github.tennaito.rsql.misc.ArgumentFormatException;
import com.github.tennaito.rsql.misc.DefaultArgumentParser;
import java.sql.Timestamp;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
// default DefaultArgumentParser can't parse Timestamps :(
public class CustomizedArgumentParser extends DefaultArgumentParser {