0

Hi below is my Spring code and pom.xml. Maven is not able to update even though I tried to force project update. Any resolution on this or direction where I am getting wrong.

package com.boot;

import org.springframework.*;

@SpringBootApplication
public class App 
{
   public static void main( String[] args )
   {
      System.out.println("Hello World");
   }
}

pom

<groupId>com.boot</groupId>
<artifactId>das-boot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.4.2.RELEASE</version>
</parent>

<name>das-boot</name>
<url>http://maven.apache.org</url>

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <start-class>com.boot.App</start-class>
</properties>

<dependencies>
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>3.8.1</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
 </dependencies>
</project>

I am not getting why Maven is not able to get the dependencies for my project. A

4
  • Are you getting any errors/exception? Commented Dec 8, 2016 at 5:38
  • SpringBootApplication cannot be resolved to a type Commented Dec 8, 2016 at 5:42
  • It would be much easier to identify the issue if you could post your stack trace with the question. Commented Dec 8, 2016 at 5:42
  • import org.springframework.* doesn't cover the package that @SpringBootAppliation is in. Use the correct import. If you have corrupted your local repo try mvn dependency:purge-local-repository to wipe your dependencies and have the re downloaded. Still you need to fix your imports. Commented Dec 8, 2016 at 7:53

4 Answers 4

2

I faced the same issue.
I changed the version from 2.0.5.RELEASE to 2.0.3.RELEASE to make it work

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
Sign up to request clarification or add additional context in comments.

Comments

2

Assumption

  • All the dependencies are updated for project
  • Connected with the internet :P
  • You are using either gradle or Maven

This is an exciting situation, it can be resolved by reloading the dependencies. where the situation is, Userv can build the binary (jar) but can not run the application locally.

To resolve this issue you need to update the dependencies manually.

For Maven,

mvn clean install -U

For Gradle

./gradlew clean build --refresh-dependencies

Not sure about the root cause, tries but was unable to reproduce it. Will try to improve the answer once we encounter the same trap

Comments

0

If you are fine to move to 2.x then please follow below steps:

Step 1 copy below pom

<?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.boot</groupId>
    <artifactId>das-boot</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>das-boot</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <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>

Step 2: Here is your main application class:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DasBootApplication {

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

or you can also stay with 1.4.2, just change java version to 1.6.

Comments

0

You should provide the class name in the run() method like below:

@SpringBootApplication
public static void main(String[] args) { 
    SpringApplication.run(App.class, args);
    Sytem.out.print("Started");
}

And remove the below line from pom.xml

<start-class>com.boot.App</start-class>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.