0

Hello? I'm a developer trying to study Spring Boot.
For now, I just wanted to print Hello World on a web page, so I created a controller package and a class.
I will post the entire code first.

First is the pom.xml file.

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.8.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.limsrs</groupId>
<artifactId>testproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>testproject</name>
<description>testproject for Spring Boot</description>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

</project>

Next is the TestprojectApplication.java file.

package com.limsrs.testproject;

import java.util.Arrays;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class TestprojectApplication {

    public static void main(String[] args) {
        SpringApplication.run(TestprojectApplication.class, args);
    }

    @Bean
    public CommandLineRunner commandLineRunner(ApplicationContext context) {
        return args -> {
            System.out.println("Let's inspect the beans provided by Spring Boot:");

            String[] beanNames = context.getBeanDefinitionNames();
            Arrays.sort(beanNames);
            for (String beanName : beanNames) {
                System.out.println(beanName);
            }
        };
    }
}

Last is the HelloWorldController.java file.

package com.limsrs.testproject.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloWorldController {

    @RequestMapping("/")
    public String home() {
        return "Hello World~!";
    }
}

After running the spring boot app, I tried to connect to localhost: 8080 and the login window appeared.
If you search the Internet, you will see the login method using spring-security, but not that, and you will not see the Hello World screen.

What I want to do is simply see the Hello World screen. The login window is not what I want.

limsrs
  • 19
  • 8
  • 1
    Are you sure Spring Boot not failed to run on localhost:8080 and some other Spring Security application is already running on that port? – bkbb Sep 20 '19 at 02:11
  • Can you tell me where to check? First of all, ```spring boot app``` has a project in ```testproject```. It also includes icons with two gears, such as ```configserver```. – limsrs Sep 20 '19 at 02:19
  • I did not understand "spring boot app has a project in testproject. It also includes icons with two gears, such as configserver". But when you started your spring boot app, are you getting "Started TestprojectApplication in 3.713 seconds (JVM running for 4.304)" message? Also check the content of src/main/resources/application.properties – bkbb Sep 20 '19 at 02:27
  • can you try running it on different port? @limsrs – Deadpool Sep 20 '19 at 02:32
  • Looking closely at the message, I found the message ```ERROR 9704 --- [main] org.apache.catalina.util.LifecycleBase: Failed to start component [Connector [HTTP / 1.1-8080]].``` And there is nothing in ```application.properties```. – limsrs Sep 20 '19 at 02:33
  • I found a way to change the port. ```server.port = 8100``` This will bring up ```Hello World!``` Thank you. – limsrs Sep 20 '19 at 02:35
  • I was about to say the same. So some other application was running on 8080 and that was configured with Spring Security :-) – bkbb Sep 20 '19 at 02:35
  • Do you ever know how to delete a running app on 8080? In sts boot app it is invisible except for my app. – limsrs Sep 20 '19 at 02:38
  • kill that process running on 8080 https://stackoverflow.com/questions/39632667/how-to-kill-the-process-currently-using-a-port-on-localhost-in-windows – Deadpool Sep 20 '19 at 02:41
  • you can follow the below steps to close the port https://stackoverflow.com/questions/39632667/how-to-kill-the-process-currently-using-a-port-on-localhost-in-windows – Arun Prasat Sep 20 '19 at 02:41
  • ans also can you add any error messages displayed in console @limsrs – Deadpool Sep 20 '19 at 02:42
  • It says that you can't quit because access is denied. – limsrs Sep 20 '19 at 02:52
  • Hello, @limsrs can you update the question with an error which you are getting. – Patel Romil Sep 20 '19 at 12:00
  • I ended up using Task manager. – limsrs Sep 22 '19 at 08:33

0 Answers0