Skip to content

Commit 1f65aec

Browse files
committed
Add Hello World sample apps with and without Spring Boot
1 parent 47a3550 commit 1f65aec

File tree

7 files changed

+79
-8
lines changed

7 files changed

+79
-8
lines changed

spring-shell-samples/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
<modules>
1717
<module>spring-shell-sample-hello-world</module>
18+
<module>spring-shell-sample-hello-world-spring-boot</module>
1819
<module>spring-shell-sample-catalog</module>
1920
<module>spring-shell-sample-commands</module>
2021
</modules>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.springframework.shell</groupId>
7+
<artifactId>spring-shell-samples</artifactId>
8+
<version>4.0.0-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>spring-shell-sample-hello-world-spring-boot</artifactId>
12+
<name>Spring Shell Samples - Hello World with Spring Boot</name>
13+
<packaging>jar</packaging>
14+
<description>Hello World Spring Boot based Shell application</description>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.springframework.shell</groupId>
19+
<artifactId>spring-shell-starter</artifactId>
20+
<version>${project.parent.version}</version>
21+
</dependency>
22+
23+
<dependency>
24+
<groupId>org.hibernate.validator</groupId>
25+
<artifactId>hibernate-validator</artifactId>
26+
<version>${hibernate-validator.version}</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.glassfish</groupId>
30+
<artifactId>jakarta.el</artifactId>
31+
<version>${jakarta.el.version}</version>
32+
</dependency>
33+
</dependencies>
34+
35+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.springframework.shell.samples.helloworld.boot;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.shell.core.command.annotation.Command;
6+
import org.springframework.shell.core.command.annotation.Option;
7+
8+
@SpringBootApplication
9+
public class SpringShellApplication {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(SpringShellApplication.class, args);
13+
}
14+
15+
@Command
16+
public String hello(@Option(defaultValue = "World") String name) {
17+
return "Hello " + name + "!";
18+
}
19+
20+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<configuration>
2+
3+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
4+
<layout class="ch.qos.logback.classic.PatternLayout">
5+
<Pattern>
6+
%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
7+
</Pattern>
8+
</layout>
9+
</appender>
10+
11+
<root level="info">
12+
<appender-ref ref="CONSOLE"/>
13+
</root>
14+
15+
</configuration>

spring-shell-samples/spring-shell-sample-hello-world/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<dependencies>
1717
<dependency>
1818
<groupId>org.springframework.shell</groupId>
19-
<artifactId>spring-shell-starter</artifactId>
19+
<artifactId>spring-shell-core</artifactId>
2020
<version>${project.parent.version}</version>
2121
</dependency>
2222

spring-shell-samples/spring-shell-sample-hello-world/src/main/java/org/springframework/shell/samples/helloworld/SpringShellApplication.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
package org.springframework.shell.samples.helloworld;
22

3-
import org.springframework.boot.SpringApplication;
4-
import org.springframework.boot.autoconfigure.SpringBootApplication;
3+
import org.springframework.context.ApplicationContext;
4+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5+
import org.springframework.shell.core.ShellRunner;
56
import org.springframework.shell.core.command.annotation.Command;
67
import org.springframework.shell.core.command.annotation.EnableCommand;
78
import org.springframework.shell.core.command.annotation.Option;
89

9-
@SpringBootApplication
1010
@EnableCommand(SpringShellApplication.class)
11-
@Command
1211
public class SpringShellApplication {
1312

14-
public static void main(String[] args) {
15-
SpringApplication.run(SpringShellApplication.class, args);
13+
public static void main(String[] args) throws Exception {
14+
ApplicationContext context = new AnnotationConfigApplicationContext(SpringShellApplication.class);
15+
ShellRunner runner = context.getBean(ShellRunner.class);
16+
runner.run(args);
1617
}
1718

1819
@Command

spring-shell-samples/spring-shell-sample-hello-world/src/main/resources/application.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)