Spring


Resources for Spring

Spring

Initialization

Im1

Thymeleaf

Running a specific environment

Config files

Examples:

application-production.properties

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/db
spring.datasource.username=root
spring.datasource.password=root

application-staging.properties

spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
spring.datasource.username=sa
spring.datasource.password=sa

pom.xml

	<profiles>
		<profile>
			<id>dev</id>
			<build>
				<plugins>
					<plugin>
						<groupId>org.springframework.boot</groupId>
						<artifactId>spring-boot-maven-plugin</artifactId>
						<configuration>
							<profiles>
								<profile>dev</profile>
							</profiles>
						</configuration>
					</plugin>
				</plugins>
			</build>
		</profile>
		<profile>
			<id>prod</id>
			<build>
				<plugins>
					<plugin>
						<groupId>org.springframework.boot</groupId>
						<artifactId>spring-boot-maven-plugin</artifactId>
						<configuration>
							<profiles>
								<profile>prod</profile>
							</profiles>
						</configuration>
					</plugin>
				</plugins>
			</build>
		</profile>
	</profiles>

Running specific

Dev environment

  • Locally with spring-boot:run
    • $ mvn spring-boot:run -Pdev
  • Locally with the produced jar
    • $ java -jar -Dspring.profiles.active=dev myapp.jar

Production environment

  • Locally with spring-boot:run
    • $ mvn spring-boot:run -Pprod
  • Locally with the produced jar
    • $ java -jar -Dspring.profiles.active=production myapp.jar

Other Resources