Skip to content

Commit

Permalink
fix: application et servlet initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin-Guillemin committed Nov 27, 2023
1 parent 4e53a2f commit 5da0ce1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
26 changes: 24 additions & 2 deletions src/main/java/fr/recia/collabsoft/CollabsoftApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,36 @@
*/
package fr.recia.collabsoft;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

@Slf4j
@SpringBootApplication
public class CollabsoftApplication {

public static void main(String[] args) {
SpringApplication.run(CollabsoftApplication.class, args);
public static void main(String[] args) throws UnknownHostException {
SpringApplication app = new SpringApplication(CollabsoftApplication.class);
app.setBannerMode(Banner.Mode.OFF);

Environment env = app.run(args).getEnvironment();
log.info(
"Access URLs:" +
"\n----------------------------------------------------------" +
"\n\tLocal: \t\thttp://127.0.0.1:{}" +
"\n\tExternal: \thttp://{}:{}" +
"\n\tProfiles: \t{}" +
"\n----------------------------------------------------------",
env.getProperty("server.port"),
InetAddress.getLocalHost().getHostAddress(),
env.getProperty("server.port"),
env.getProperty("spring.profiles.active")
);
}

}
20 changes: 19 additions & 1 deletion src/main/java/fr/recia/collabsoft/ServletInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,32 @@
*/
package fr.recia.collabsoft;

import fr.recia.collabsoft.configuration.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.Banner;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

@Slf4j
public class ServletInitializer extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(CollabsoftApplication.class);
return application
.profiles(addDefaultProfile())
.bannerMode(Banner.Mode.OFF)
.sources(CollabsoftApplication.class);
}

private String addDefaultProfile() {
String profile = System.getProperty("spring.profiles.active");
if (profile != null) {
log.info("Running with Spring profile(s) : {}", profile);
return profile;
}

log.warn("No Spring profile configured, running with default configuration");
return Constants.SPRING_PROFILE_DEVELOPMENT;
}

}
14 changes: 11 additions & 3 deletions src/main/java/fr/recia/collabsoft/configuration/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@

public class Constants {

public static final String PROPERTIES_TO_JSON_DELIMITER = "\",\"";
public static final String PROPERTIES_TO_JSON_PREFIX = "[\"";
public static final String PROPERTIES_TO_JSON_SUFFIX = "\"]";
private Constants() {
throw new IllegalStateException("Utility class");
}

public static final String PROPERTIES_TO_JSON_DELIMITER = "\", \"";
public static final String PROPERTIES_TO_JSON_PREFIX = "[ \"";
public static final String PROPERTIES_TO_JSON_SUFFIX = "\" ]";

public static final String SPRING_PROFILE_DEVELOPMENT = "dev";
public static final String SPRING_PROFILE_PRODUCTION = "prod";
public static final String SPRING_PROFILE_TEST = "test";

}

0 comments on commit 5da0ce1

Please sign in to comment.