Skip to main content

๐ŸŒฑ Spring Boot Interview Series – Q5 ๐Ÿ’ก: Server Ports, HTTPS, Profiles & Hidden Tricks ๐Ÿš€๐Ÿ”๐Ÿ› ️

๐ŸŒ Changing the Default Server Port

By default, Spring Boot runs your application on port 8080. You can change this by adding the following in your application.properties:

server.port=9090

Or in application.yml:

server:

  port: 9090

๐Ÿ’ก Tip: You can set server.port=0 to make Spring Boot choose a random free port — useful for integration tests.
Common Mistake: Changing the port in @Bean methods like TomcatServletWebServerFactory but forgetting to remove server.port from application.properties can cause confusion. Properties file wins unless overridden by command-line args.

๐Ÿ”’ Enabling HTTPS in Spring Boot

To enable HTTPS, you’ll need a keystore file (e.g., keystore.p12) and then configure Spring Boot:

server.port=8443

server.ssl.key-store=classpath:keystore.p12

server.ssl.key-store-password=changeit

server.ssl.keyStoreType=PKCS12

server.ssl.keyAlias=tomcat

๐Ÿ’ก Unknown Fact: Spring Boot can run HTTP and HTTPS together — just define another TomcatConnectorCustomizer bean for port 8080 while keeping 8443 as HTTPS.
Common Mistake: Using a self-signed certificate in production without adding it to the truststore will break API calls from browsers and other services.

๐Ÿšซ Disabling the Web Server

If you’re creating a non-web application (like a batch job or CLI tool), you can disable the embedded server:

@SpringBootApplication

public class MyApp {

    public static void main(String[] args) {

        SpringApplication app = new SpringApplication(MyApp.class);

        app.setWebApplicationType(WebApplicationType.NONE);

        app.run(args);

    }

}

Or via properties:

spring.main.web-application-type=none
๐Ÿ’ก Tip: This reduces startup time and memory usage since Tomcat/Jetty/Undertow is not loaded.
Common Mistake: Developers forget to remove web-related beans/controllers when disabling the server — Spring will still try to load them and fail.

๐Ÿ“ฆ Default Packaging Type in Spring Boot

When you create a Spring Boot project using Spring Initializr, the default packaging type is JAR. This means the embedded server (Tomcat, by default) is inside your packaged app, so you can run it with:

java -jar myapp.jar
๐Ÿ’ก Extra Info: You can switch to WAR if you want to deploy in external servers like Apache Tomcat — just change <packaging>war</packaging> in Maven.
Common Mistake: Switching to WAR but forgetting to extend SpringBootServletInitializer will cause the app not to start on an external server.

๐Ÿ“„ application.properties vs application.yml

Both are used for externalizing configuration, but:

  • application.properties: Key-value format, simpler, familiar for many developers.
  • application.yml: YAML format, supports hierarchy, cleaner for nested configs.
๐Ÿ’ก Extra Info: Spring Boot loads both by default — if both exist, application.properties overrides application.yml for the same property.
Common Mistake: Using tabs in .yml — YAML does not support tabs, only spaces, causing ScannerException.

๐Ÿงฉ How Profiles Work in Spring Boot

Profiles let you group configurations for different environments (dev, test, prod). You can create files like:

application-dev.properties

application-prod.properties

Activate a profile via:

spring.profiles.active=dev
๐Ÿ’ก Unknown Fact: You can activate multiple profiles at once using spring.profiles.active=dev,qa.
Common Mistake: Forgetting to set the active profile in production — your app might accidentally run with dev settings (like an in-memory DB).

๐ŸŽฌ Wrapping Up

Wow! Today we explored some of Spring Boot’s hidden gems — from changing server ports ๐Ÿ–ฅ️, enabling HTTPS ๐Ÿ”, disabling the web server ๐Ÿšซ, understanding default packaging ๐Ÿ“ฆ, comparing application.properties vs application.yml ๐Ÿ—‚️, to managing profiles ๐ŸŒฑ.

๐Ÿ’ก Here’s what you should take away:

  • Spring Boot makes life easier, but small misconfigurations (wrong port, YAML indentation, wrong profile) can cause big headaches ๐Ÿ˜…
  • Always double-check your spring.profiles.active and SSL setups before deploying to production ⚠️
  • Use embedded servers wisely — or disable them for non-web apps to save resources ๐Ÿ’ช
  • Know when to use JAR vs WAR packaging depending on deployment targets ๐Ÿ—️

๐Ÿ”ฅ My challenge to you: Try these configs in a small test project and see how changing one thing can affect the entire app. It’s a fun way to learn & remember! ๐Ÿš€

๐Ÿ’ฌ I’d love to hear from you: Which Spring Boot trick surprised you the most? Drop your thoughts in the comments below ๐Ÿ‘‡ — let’s learn together!

๐Ÿ“Œ Hashtags: #SpringBoot #JavaDeveloper #InterviewPrep #JavaLearning #SpringTips #Microservices #CodingLife #TechBlog

Comments

Popular posts from this blog

๐Ÿ” Is final Really Final in Java? The Truth May Surprise You ๐Ÿ˜ฒ

๐Ÿ’ฌ “When I was exploring what to do and what not to do in Java, one small keyword caught my eye — final . I thought it meant: locked, sealed, frozen — like my fridge when I forget to defrost it.”   But guess what? Java has its own meaning of final… and it’s not always what you expect! ๐Ÿ˜… Let’s break it down together — with code, questions, confusion, jokes, and everything in between. ๐ŸŽฏ The Confusing Case: You Said It's Final... Then It Changed?! ๐Ÿซ  final List<String> names = new ArrayList <>(); names.add( "Anand" ); names.add( "Rahul" ); System.out.println(names); // [Anand, Rahul] ๐Ÿคฏ Hold on... that’s final , right?! So how on earth is it still changing ? Time to dive deeper... ๐Ÿง  Why Is It Designed Like This? Here’s the key secret: In Java, final applies to the reference , not the object it points to . Let’s decode this like a spy mission ๐Ÿ•ต️‍♂️: Imagine This: final List<String> names = new ArrayList <>(); Be...

๐ŸŒŸ My Journey – From Zero to Senior Java Tech Lead ๐ŸŒŸ

 There’s one thing I truly believe… If I can become a Java developer, then anyone in the world can. ๐Ÿ’ฏ Sounds crazy? Let me take you back. ๐Ÿ•“ Back in 2015… I had zero coding knowledge . Not just that — I had no interest in coding either. But life has its own plans. In 2016, I got a chance to move to Bangalore and joined a Java course at a training center. That’s where it all started — Every day, every session made me feel like: "Ohhh! Even I can be a developer!" That course didn’t just teach Java — it gave me confidence . ๐Ÿงช Two Life-Changing Incidents 1️⃣ The Interview That Wasn't Planned Halfway through my course, I had to urgently travel to Chennai to donate blood to a family member. After that emotional rollercoaster, I found myself reflecting on my skills and the future. The next day, as I was preparing for my move to Bangalore to complete the remaining four months of my course, I randomly thought — "Let me test my skills... let me just see...

๐ŸŽข Java Loops: Fun, Fear, and ForEach() Fails

๐ŸŒ€ Oops, I Looped It Again! — The Ultimate Java Loop Guide You Won't Forget “I remember this question from one of my early interviews — I was just 2 years into Java and the interviewer asked, ‘Which loop do you prefer and why?’” At first, I thought, “Duh! for-each is cleaner.” But then he grilled me with cases where it fails. ๐Ÿ˜ต That led me to explore all loop types, their powers, and their pitfalls. Let’s deep-dive into every major Java loop with examples &  real-world guidance so you'll never forget again. ๐Ÿ” Loop Type #1: Classic For Loop — “The Old Reliable” ✅ When to Use: You need an index You want to iterate in reverse You want full control over loop mechanics ✅ Good Example: List<String> names = List.of("A", "B", "C"); for (int i = 0; i < names.size(); i++) { System.out.println(i + ": " + names.get(i)); } ๐Ÿ”ฅ Reverse + Removal Example: List<String> item...