This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
В разделе рассматриваются Профили(Profiles) и Свойства(Properties) | |
1. Environment(org.springframework.core.env) - абстракция для профилей (определяет активные кастомные и по дефолту | |
профили, которые включают множества бинов) и абстракция для свойств (позволяет конфигурировать и считывать свойства) | |
2. Properties sources: | |
- properties file | |
- JVM system properties | |
- system env properties | |
- JNDI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. xml/annotation? Зависит от ситуации. Аннотации пишутся в контексте использования. Это коротко и просто. XML же | |
не изменяет никак исходный код (POJO) | |
2. @Required. Необходима, чтобы убедиться что связывание было произведено. Рекомендуется делать доп проверки в init | |
методе. Лучще использовать @Autowired с параметром required |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 и мб вручную взяты оттуда |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. depends-on | |
При определении бинов используй параметр depends-on для указания бина, который дб инициализирован до этого бина. | |
Это полезно, например, если в статическом инициализаторе главного бина есть код для загрузки классов (Class.forName), | |
которые нужны зависимому бину. | |
<bean id="..." class="..." depends-on="..."/> | |
2. autowire | |
* no - не использовать автосвязывание (по умолчанию) | |
* byName - искать зависимости в зависимости от имен свойств | |
* byType - искать зависимости в зависимости от типом свойств. Если много кандидатов - выбросить ошибку, но если тип | |
свойства - коллекция, то собрать всех кандидотов в неё |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
NewerOlder