Skip to content

Instantly share code, notes, and snippets.

View thergbway's full-sized avatar

Andrey Selivanov thergbway

  • Saint Petersburg, Russia
View GitHub Profile
@thergbway
thergbway / ! Spring IOC Profiles and Properties.txt
Created October 12, 2016 05:38
SPRING. INVERSION OF CONTROL. PROFILES AND PROPERTIES
В разделе рассматриваются Профили(Profiles) и Свойства(Properties)
1. Environment(org.springframework.core.env) - абстракция для профилей (определяет активные кастомные и по дефолту
профили, которые включают множества бинов) и абстракция для свойств (позволяет конфигурировать и считывать свойства)
2. Properties sources:
- properties file
- JVM system properties
- system env properties
- JNDI
@thergbway
thergbway / ! Spring IOC Java Config.txt
Created October 11, 2016 02:38
SPRING. INVERSION OF CONTROL. JAVA CONFIG
1. xml/annotation? Зависит от ситуации. Аннотации пишутся в контексте использования. Это коротко и просто. XML же
не изменяет никак исходный код (POJO)
2. @Required. Необходима, чтобы убедиться что связывание было произведено. Рекомендуется делать доп проверки в init
методе. Лучще использовать @Autowired с параметром required
@thergbway
thergbway / ! Spring IOC Scopes.txt
Last active October 11, 2016 02:38
SPRING. INVERSION OF CONTROL. SCOPES
Available scopes:
* singletone. Один на контейнер. По умолчанию
* prototype. При каждом запросе новый бин. Spring не управляет полным циклом данного бина(не вызывает destroy). Use custom PostProcessor
* thread. По умолчанию СКРЫТ. Один на поток
* 'custom_scope'
-Only in Spring Web. Such beans should be created in XmlWebApplicationContext:
* request. Один на Http Request
* session. Один на Http Session
* globalSession. Один на глобальную Http сессию. Применимо в основном к портлетам(Portlet)
* application. Один на ServletContext, сохраняется в атрибуты ServletContext и мб вручную взяты оттуда
@thergbway
thergbway / ! Spring IOC Dependencies.txt
Last active October 10, 2016 17:54
SPRING. INVERSION OF CONTROL. DEPENDENCIES
1. depends-on
При определении бинов используй параметр depends-on для указания бина, который дб инициализирован до этого бина.
Это полезно, например, если в статическом инициализаторе главного бина есть код для загрузки классов (Class.forName),
которые нужны зависимому бину.
<bean id="..." class="..." depends-on="..."/>
2. autowire
* no - не использовать автосвязывание (по умолчанию)
* byName - искать зависимости в зависимости от имен свойств
* byType - искать зависимости в зависимости от типом свойств. Если много кандидатов - выбросить ошибку, но если тип
свойства - коллекция, то собрать всех кандидотов в неё
@thergbway
thergbway / ! PropertyFileTest.java
Last active October 6, 2016 17:57
PROPERTY FILES. HOW TO USE THEM
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.Reader;
import java.util.Properties;
public class PropertyFileTest {
public static void main(String[] args) {
Properties props = new Properties();
@thergbway
thergbway / ! Java 8 Date&Time API description.txt
Last active October 3, 2016 18:08
JAVA 8 DATE/TIME API DESCRIPTION
For more info go to https://docs.oracle.com/javase/tutorial/datetime/iso/index.html
Java 8 Date/Time was developed by a developer of Joda time(http://www.joda.org/joda-time/)
Java 8 Date/Time API Overview:
- Uses ISO8601(http://www.iso.org/iso/home/standards/iso8601.htm)
as the default calendar(Gregorian calendar system, used globally defacto standart for representing date and time).
To switch calendar use java.time.chrono package(Hijrah or
Thai Buddhist calendar system or create your own)
- Uses the Unicode Common Locale Data Repository(CLDR, http://cldr.unicode.org/).
It supports the world's languages and contains the world's largest collection of locale data available.
@thergbway
thergbway / pom.xml Maven default POM
Last active October 15, 2016 02:53
Maven default POM
<?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></groupId>
<artifactId></artifactId>
<version>1.0-SNAPSHOT</version>
<name></name>
import java.util.*;
public class Main {
public static void main(String[] args) {
//List.sublist()
{
//Можем обрабатывать только часть коллекции. Результат можно изменять, как будто это кусок
//исходной коллекции
List<Integer> list = new LinkedList<>();
list.addAll(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));