Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

sivaprasadreddy/intellij-live-templates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

7 Commits

Repository files navigation

Intellij IDEA LiveTemplates

These are my custom IntelliJ IDEA Live Templates for Java that I am currently using.

Export and Import

You can import LiveTemplates by File -> Manage IDE Settings -> Import Settings -> Select settings.zip

You can export LiveTemplates by File -> Manage IDE Settings -> Export Settings -> Select Live Templates -> Ok

Java

  1. log - Adds SLF4J Logger
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger($CLASS$.class);
  1. at - AssertJ assertThat()
org.assertj.core.api.Assertions.assertThat($END$)

JPA

  1. jpa-entity - JPA Entity
@jakarta.persistence.Entity
class $entity$ {

@jakarta.persistence.Id
@jakarta.persistence.GeneratedValue
private java.lang.Long id;
private java.lang.String name;

public $entity$() {}

public $entity$(String name) {
this.name = name;
}

public java.lang.Long getId() {
return id;
}

public void setId(java.lang.Long id) {
this.id = id;
}

public java.lang.String getName() {
return name;
}

public void setName(java.lang.String name) {
this.name = name;
}

@java.lang.Override
public java.lang.String toString() {
return "$entity${" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
  1. jpa-entity-lombok - JPA Entity with Lombok
@lombok.Setter
@lombok.Getter
@lombok.AllArgsConstructor
@lombok.NoArgsConstructor
@jakarta.persistence.Entity
class $name$ {
@jakarta.persistence.Id
@jakarta.persistence.GeneratedValue
private Long id;
private String name;
}
  1. jpa-entity-id-seq - JPA Entity Id of Sequence Generator Type
@jakarta.persistence.Id
@jakarta.persistence.GeneratedValue(strategy = jakarta.persistence.GenerationType.SEQUENCE, generator = "$table$_id_generator")
@jakarta.persistence.SequenceGenerator(name = "$table$_id_generator", sequenceName = "$table$_id_seq", allocationSize = 50)
private Long id;
  1. jpa-many-to-many - JPA Entity property of ManyToMany Type
@jakarta.persistence.ManyToMany(cascade = {jakarta.persistence.CascadeType.PERSIST, jakarta.persistence.CascadeType.MERGE})
@jakarta.persistence.JoinTable(
name = "$join_table_name$",
joinColumns = {@jakarta.persistence.JoinColumn(name = "$id_column$", referencedColumnName = "$id_ref_column$")},
inverseJoinColumns = {@jakarta.persistence.JoinColumn(name = "$id_join_column$", referencedColumnName = "$id_ref_join_column$")})
private Set<$CLASS$> $name$;

SpringBoot

  1. boot-controller - SpringMVC REST Controller
@org.springframework.web.bind.annotation.RestController
@org.springframework.web.bind.annotation.RequestMapping("/api")
class $CLASS$ {

}
  1. boot-service - SpringBoot Service
@org.springframework.stereotype.Service
@org.springframework.transaction.annotation.Transactional(readOnly=true)
public class $CLASS$ {

}
  1. boot-app-properties - SpringBoot ApplicationProperties binding class
@org.springframework.boot.context.properties.ConfigurationProperties(prefix = "$prefix$")
public class $CLASS$ {

}
  1. boot-clr - SpringBoot CommandLineRunner
@org.springframework.stereotype.Component
public class $CLASS$ implements org.springframework.boot.CommandLineRunner {

@Override
public void run(String... args) throws Exception {

}
}
  1. boot-add-cors-mappings - SpringBoot WebMvcConfig addCorsMappings
@Override
public void addCorsMappings(org.springframework.web.servlet.config.annotation.CorsRegistry registry) {
registry.addMapping("/api/**")
.allowedMethods("*")
.allowedHeaders("*")
.allowedOriginPatterns("*")
.allowCredentials(true);
}
  1. boot-cors-filter - SpringBoot CORS Filter
@org.springframework.context.annotation.Bean
public org.springframework.boot.web.servlet.FilterRegistrationBean simpleCorsFilter() {
org.springframework.web.cors.UrlBasedCorsConfigurationSource source = new org.springframework.web.cors.UrlBasedCorsConfigurationSource();
org.springframework.web.cors.CorsConfiguration config = new org.springframework.web.cors.CorsConfiguration();
config.setAllowCredentials(true);
config.setAllowedOrigins(java.util.Collections.singletonList("http://localhost:4200"));
config.setAllowedMethods(java.util.Collections.singletonList("*"));
config.setAllowedHeaders(java.util.Collections.singletonList("*"));
source.registerCorsConfiguration("/**", config);
org.springframework.boot.web.servlet.FilterRegistrationBean bean = new org.springframework.boot.web.servlet.FilterRegistrationBean(new org.springframework.web.filter.CorsFilter(source));
bean.setOrder(org.springframework.core.Ordered.HIGHEST_PRECEDENCE);
return bean;
}
  1. boot-open-api-config - SpringBoot OpenAPI Configuration
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class $CLASS$ {
@Bean
public io.swagger.v3.oas.models.OpenAPI springShopOpenAPI() {
return new io.swagger.v3.oas.models.OpenAPI()
.info(info())
.externalDocs(externalDocumentation())
.schemaRequirement("bearerAuth", jwtSecurityScheme())
;
}

private io.swagger.v3.oas.models.info.Info info() {
return new io.swagger.v3.oas.models.info.Info()
.title("API Title")
.description("API description")
.version("v0.0.1")
.license(new io.swagger.v3.oas.models.info.License().name("MIT"));
}

private io.swagger.v3.oas.models.ExternalDocumentation externalDocumentation() {
return new io.swagger.v3.oas.models.ExternalDocumentation()
.description("API Documentation")
.url("https://github.com/user/repo/README.md");
}

private io.swagger.v3.oas.models.security.SecurityScheme jwtSecurityScheme() {
io.swagger.v3.oas.models.security.SecurityScheme scheme = new io.swagger.v3.oas.models.security.SecurityScheme();
scheme.setName("bearerAuth");
scheme.setType(io.swagger.v3.oas.models.security.SecurityScheme.Type.HTTP);
scheme.setScheme("bearer");
scheme.setBearerFormat("JWT");
return scheme;
}
}
  1. boot-mvc-test - SpringMVC Test method
@org.springframework.beans.factory.annotation.Autowired
private org.springframework.test.web.servlet.MockMvc mockMvc;

@org.junit.jupiter.api.Test
void test$Function$() throws java.lang.Exception {
var request = org.springframework.test.web.servlet.request.MockMvcRequestBuilders
.post("")
.contentType(org.springframework.http.MediaType.APPLICATION_JSON);

mockMvc.perform(request)
.andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status().isCreated())
.andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content().contentType(org.springframework.http.MediaType.APPLICATION_JSON))
.andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath("", org.hamcrest.Matchers.is("")));
}
  1. boot-dynamic-property-registrar - Spring Boot DynamicPropertyRegistrar
@org.springframework.context.annotation.Bean
org.springframework.test.context.DynamicPropertyRegistrar dynamicPropertyRegistrar() {
return (registry) -> {
registry.add("", "");
};
}
  1. boot-datasource-jpa-properties - Spring Boot DataSource and JPA Properties
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.open-in-view=false
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.show-sql=true
#spring.jpa.properties.hibernate.format_sql=true

Testcontainers

  1. tc-magic-jdbc-url - Spring Boot TestPropertySource with Testcontainers magic JDBC URL
@org.springframework.test.context.TestPropertySource(properties = {
"spring.test.database.replace=none",
"spring.datasource.url=jdbc:tc:postgresql:17-alpine:///db"
})
  1. tc-postgres - PostgreSQLContainer
@org.testcontainers.junit.jupiter.Container
static org.testcontainers.containers.PostgreSQLContainer postgres =
new org.testcontainers.containers.PostgreSQLContainer<>("postgres:17-alpine");

SQL

  1. flyway-table - Flyway table creation script
create sequence $table$_id_seq start with 1 increment by 50;

create table $table$ (
id bigint not null default nextval('$table$_id_seq'),
created_at timestamp not null default now(),
updated_at timestamp,
primary key (id)
);

Maven

  1. jib-maven-plugin - Add Jib Maven Plugin
<plugin>
<groupId>com.google.cloud.toolsgroupId>
<artifactId>jib-maven-pluginartifactId>
<version>3.3.4version>
<configuration>
<from>
<image>eclipse-temurin:21-jreimage>
from>
<to>
<image>sivaprasadreddy/${project.artifactId}image>
<tags>
<tag>latesttag>
<tag>${project.version}tag>
tags>
to>
<container>
<ports>
<port>8080port>
ports>
container>
configuration>
plugin>
  1. git-commit-id-maven-plugin - Adds git-commit-id-maven-plugin
<plugin>
<groupId>io.github.git-commit-idgroupId>
<artifactId>git-commit-id-maven-pluginartifactId>
<executions>
<execution>
<goals>
<goal>revisiongoal>
goals>
execution>
executions>
<configuration>
<failOnNoGitDirectory>falsefailOnNoGitDirectory>
<failOnUnableToExtractRepoInfo>falsefailOnUnableToExtractRepoInfo>
<generateGitPropertiesFile>truegenerateGitPropertiesFile>
<includeOnlyProperties>
<includeOnlyProperty>^git.branch$includeOnlyProperty>
<includeOnlyProperty>^git.commit.id.abbrev$includeOnlyProperty>
<includeOnlyProperty>^git.commit.user.name$includeOnlyProperty>
<includeOnlyProperty>^git.commit.message.full$includeOnlyProperty>
includeOnlyProperties>
configuration>
plugin>
  1. spotless-maven-plugin - Adds spotless-maven-plugin
<plugin>
<groupId>com.diffplug.spotlessgroupId>
<artifactId>spotless-maven-pluginartifactId>
<version>2.44.2version>
<configuration>
<java>
<importOrder />
<removeUnusedImports />
<palantirJavaFormat>
<version>2.50.0version>
palantirJavaFormat>
<formatAnnotations />
java>
configuration>
<executions>
<execution>
<phase>compilephase>
<goals>
<goal>checkgoal>
goals>
execution>
executions>
plugin>
  1. frontend-maven-plugin-npm - Adds frontend-maven-plugin with NPM
<plugin>
<groupId>com.github.eirslettgroupId>
<artifactId>frontend-maven-pluginartifactId>
<version>1.15.1version>
<configuration>
<workingDirectory>${project.basedir}/../frontendworkingDirectory>
<nodeVersion>v20.14.0nodeVersion>
configuration>
<executions>
<execution>
<id>install node and npmid>
<goals>
<goal>install-node-and-npmgoal>
goals>
<phase>generate-resourcesphase>
execution>
<execution>
<id>npm installid>
<goals>
<goal>npmgoal>
goals>
<phase>generate-resourcesphase>
<configuration>
<arguments>installarguments>
configuration>
execution>
<execution>
<id>npm buildid>
<goals>
<goal>npmgoal>
goals>
<phase>generate-resourcesphase>
<configuration>
<environmentVariables>
<CI>trueCI>
environmentVariables>
<arguments>run buildarguments>
configuration>
execution>
executions>
plugin>
  1. frontend-maven-plugin-yarn - Adds frontend-maven-plugin with YARN
<plugin>
<groupId>com.github.eirslettgroupId>
<artifactId>frontend-maven-pluginartifactId>
<version>1.15.1version>
<executions>
<execution>
<id>install node and yarnid>
<goals>
<goal>install-node-and-yarngoal>
goals>
<configuration>
<workingDirectory>${project.basedir}/../frontendworkingDirectory>
<nodeVersion>v20.14.0nodeVersion>
<yarnVersion>v1.22.22yarnVersion>
configuration>
execution>
<execution>
<id>yarn installid>
<goals>
<goal>yarngoal>
goals>
<phase>generate-resourcesphase>
<configuration>
<arguments>installarguments>
configuration>
execution>
<execution>
<id>yarn run buildid>
<goals>
<goal>yarngoal>
goals>
<configuration>
<arguments>run buildarguments>
configuration>
execution>
executions>
plugin>
  1. maven-resources-plugin - Adds maven-resources-plugin
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-resources-pluginartifactId>
<version>3.3.1version>
<executions>
<execution>
<id>Copy UI build content to publicid>
<phase>generate-resourcesphase>
<goals>
<goal>copy-resourcesgoal>
goals>
<configuration>
<outputDirectory>${project.build.directory}/classes/publicoutputDirectory>
<overwrite>trueoverwrite>
<resources>
<resource>
<directory>${project.basedir}/../frontend/builddirectory>
resource>
resources>
configuration>
execution>
executions>
plugin>

Docker

  1. boot-Dockerfile - Creates multistage Dockerfile for Spring Boot application
# the first stage of our build will extract the layers
FROM eclipse-temurin:21-jre as builder
WORKDIR application
ARG JAR_FILE=target/*.jar
#ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract

# the second stage of our build will copy the extracted layers
FROM eclipse-temurin:21-jre
WORKDIR application
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"]

About

Intellij IDEA Live Templates

Resources

Readme

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published