IntelliJ IDEA

From Rasim SEN - Knowledge Base/Java/Springframework/Microservices/Cloud-AWS/AI
Jump to: navigation, search

https://www.jetbrains.com/idea/download/#section=windows

Register a GitHub account in IntelliJ IDEA

https://www.jetbrains.com/help/idea/manage-projects-hosted-on-github.html

SPRING INITIALIZR

https://start.spring.io/

Plugins

FindBugs-IDEA

Checkstyle-IDEA (Configure to config/checkstyle/checkstyle.xml)

SonarLint (Configure to server http://si-jenkins01.dev.setl.io:8081)

ShortCuts

MacOs Shortcuts *****


Eclipse IntelliJ IDEA Description
F4 ctrl+h show the type hierarchy
ctrl+alt+g ctrl+alt+F7 find usages
ctrl+shift+u ctrl+f7 finds the usages in the same file
alt+shift+r shift+F6 rename
ctrl+shift+r ctrl+shift+N find file / open resource
ctrl+shift+x, j ctrl+shift+F10 run (java program)
ctrl+shift+o ctrl+alt+o organize imports
ctrl+o ctrl+F12 show current file structure / outline
ctrl+shift+m ctrl+alt+V create local variable refactoring
syso ctrl+space sout ctrj+j System.out.println(“”)
alt + up/down ctrl + shift + up/down move lines
ctrl + d ctrl + y delete current line
??? alt + h show subversion history
ctrl + h ctrl + shift + f search (find in path)
“semi” set in window-> preferences ctrl + shift + enter if I want to add the semi-colon at the end of a statement
ctrl + 1 or ctrl + shift + l ctrl + alt + v introduce local variable
alt + shift + s alt + insert generate getters / setters
ctrl + shift + f ctrl + alt + l format code
ctrl + y ctrl + shift + z redo
ctrl + shift + c ctrl + / comment out lines (my own IDEA shortcut definition for comment/uncomment on german keyboard layout on laptop: ctrl + shift + y)
ctrl + alt + h ctrl + alt + h (same!) show call hierarchy
none ? ctrl + alt + f7 to jump to one of the callers of a method
ctrl + shift + i alt + f8 evaluate expression (in debugger)
F3 ctrl + b go to declaration (e.g. go to method)
ctrl + l ctrl + g go to line

https://www.jetbrains.com/help/idea/configuring-keyboard-and-mouse-shortcuts.html

https://www.catalysts.cc/en/wissenswertes/intellij-idea-and-eclipse-shortcuts/

IntelliJ - Git Setting

https://www.youtube.com/watch?v=uUzRMOCBorg

Tips & Tricks

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SpringBootApplication
@ComponentScan("com.oasissofttech.forotherpackagebeans")//default is main class package and sub-packages
public SpringMainClass {
	private static Logger LOGGER = LoggerFactory.getLogger(SpringMainClass.class);

	public static void main(Stirng[] args){
		ApplicationContext applicationContext = SpringApplication.run(SpringMainClass.class,args);
		
		PersonDAO personDao = applicationContext.getBean(PersonDAO.class);
		
		LOGGER.info("{}",personDao);
	}	
}	

...
..
@Component
@Scope(value=ConfigurableBeanFactory.SCOPE_PROTOTYPE, 
		proxyMode = ScopedProxyMode.TARGET_CLASS)
public class JdbcConnection{
	public JdbcConnection{
		System.out.println("JDBC connection");
	}
}

@PostConstruct
public void postConstruct(){
	LOGGER.info("postConstruct");
}

@PreDestroy
public void preDestroy(){
	LOGGER.info("preDestroy");
}

application.properties file

   logging.level.org.springframework = debug
   logging.level.root=debug #springboot
   spring.jpa.show-sql=true
   spring.h2.console.enabled=true

Mockito

@RunWith(MockitoJUnitRunner.class)
public class MockitoTest{
  @Mock
  DataService dataServiceMock;

  @InjectMocks
  SomeBusinessImpl businessImpl;

  @Test
  public void testCase1(){
    when(dataServiceMock.retrieveAllData()).thenReturn(new int[]{24,15,3});
    assertEquals(24,businessImpl.findTheGreatestFromAllData());
  }
  ..
  ..
}

Spring Unit Testing with an XML Context

@ContextConfiguration(location="/applicationContext.xml")

Spring Boot Actuator

<dependencies>
  <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-actuator</artifactId>
  </dependency>
  <dependency>
     <groupId>org.springframework.data</groupId>
     <artifactId>spring-data-rest-hal-browser</artifactId>
  </dependency>
</dependencies>

actuator url: http://locahost:8080/application - The HAL Browser

Spring Boot Developer Tools

no need to restart server/application, it is automatically pick up

<dependencies>
....
  <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-devtools</artifactId>
  </dependency>
...
</dependencies>