1. Press Ctrl+Alt+S
2. Look for File and Code templates
3. In Includes tab chose File Header
4. Add:
/**
* @author Arina Ielchiieva
* Date: ${DATE}
* Time: ${TIME}
*/
Monday, 22 June 2015
Friday, 19 June 2015
Class < ? > vs Class usage
Class // An unknown class (raw type)
Class<?> // An unknown class (generic version)
Class<String> // The String class
Since Java 1.5 you should use the generic form wherever possible.
Class
Class<?> // An unknown class (generic version)
Class<String> // The String class
Since Java 1.5 you should use the generic form wherever possible.
Class<?>
clearly states that you mean "an unknown class".Class
<?>
shows that you're intentionally writing Java 5-level code that doesn't know or care what class you are dealing with. Leaving out the makes it look like old code or code written by someone who hasn't learned generics yet.
How to view detailed information about Intellij Idea warnings?
Press Alt+Ctrl+S
Search for "Java Compiler"
In "Additional command line parameters:" type the following:-Xlint:unchecked
and recompile class again.
Search for "Java Compiler"
In "Additional command line parameters:" type the following:-Xlint:unchecked
and recompile class again.
How To Acсess Target Object Behind a Spring Proxy?
If you have @Autowired spring bean but for some reason (preferably for unit testing purposes in order to stub something) you want to get target object behind Spring proxy:
((Advised)yourAutowiredBean).getTargetSource().getTarget();
AopUtils.isJdkDynamicProxy(yourAutowiredBean) - can confirm you got proxied object if you have any doubts.
((Advised)yourAutowiredBean).getTargetSource().getTarget();
AopUtils.isJdkDynamicProxy(yourAutowiredBean) - can confirm you got proxied object if you have any doubts.
Wednesday, 17 June 2015
Which pid is using your port?
Show which pid uses your port:
netstat -a -n -o | find "your_port [ex: 9191]"
To kill pid from console: taskkill /pid pid_number
netstat -a -n -o | find "your_port [ex: 9191]"
To kill pid from console: taskkill /pid pid_number
Good DataSource
DriverManagerDataSource by Spring can act weird sometimes, so the best choice to use Apache data source: BasicDataSource.
Configuration:
@Bean
public DataSource dataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setUrl(JDBC_URL);
dataSource.setUsername(USERNAME);
dataSource.setPassword(PASSWORD);
dataSource.setDriverClassName(DRIVER_CLASS_NAME);
}
Maven:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.1</version>
</dependency>
How to match any enum?
Matchers.any(MyEnum.class):
when(serviceMock.preview(anyString(), any(DataSourceEnum.class)).thenReturn(anyMapOf(String.class, Collection.class)
when(serviceMock.preview(anyString(), any(DataSourceEnum.class)).thenReturn(anyMapOf(String.class, Collection.class)
Subscribe to:
Posts (Atom)