Skip to content

Instantly share code, notes, and snippets.

@tsaqib
Created May 27, 2016 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsaqib/7aa1f9aba1a8292a4d98e07aaa3f8b85 to your computer and use it in GitHub Desktop.
Save tsaqib/7aa1f9aba1a8292a4d98e07aaa3f8b85 to your computer and use it in GitHub Desktop.
A bootstrapper for SpringBoot example application
echo -e '\nMake sure you have installed & configured JDK and Maven.'
echo -e '-----'
cat >pom.xml <<EOL
<?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>com.example</groupId>
<artifactId>example</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
EOL
mkdir -p src/main/java/hello
cat >src/main/java/hello/ExampleController.java <<EOL
package example;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
@RestController
public class ExampleController {
@RequestMapping("/")
public String index() {
return "Hey!";
}
}
EOL
cat >src/main/java/hello/Application.java <<EOL
package example;
import java.util.Arrays;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
}
}
EOL
cat >run.sh <<EOL
echo -e '\nOnce launched, you should navigate to http://localhost:8080/'
echo -e '-----\n'
mvn package && java -jar target/example-0.1.0.jar
EOL
chmod 777 run.sh
echo -e 'Bootstrapped.\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment