3

EDIT-UPDATE: I've created a brand new project following this tutorial and I've noticed that, after configuring the pom, the problem is if I add

@EnableAuthorizationServer
@EnableResourceServer

annotations for the Application class.

I am new to Spring Boot and I've created a simple working application with persistence, and now I'm trying to add spring security jwt but it's not working.
Here is my project structure:

enter image description here

Since there would be too much code, here you can find player class code, playersapplication, playerserviceDB and playerscontroller.
I've followed different answers here, but I couldn't fin a solution. I can't get where is the list it is complaining about when showing me this error:

***************************
APPLICATION FAILED TO START
***************************

Description:

Field configurers in org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration required a bean of type 'java.util.List' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'java.util.List' in your configuration.

My application.properties file is the following:

spring.jpa.database=POSTGRESQL
spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://localhost:5432/testdb
spring.datasource.username=postgres
spring.datasource.password=admin
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update

While this is pom.xml:

<?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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>test</name>
    <description>Demo project 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-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

 <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

 <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.5</version>
</dependency>

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-jwt</artifactId>
    <version>1.0.10.RELEASE</version>
</dependency>

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-config</artifactId>
    <version>5.1.4.RELEASE</version>
</dependency>

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-core</artifactId>
    <version>5.0.0.RELEASE</version>
 </dependency>

 <dependency>
    <groupId>org.springframework.security.oauth</groupId>
    <artifactId>spring-security-oauth2</artifactId>
    <version>2.3.5.RELEASE</version>
</dependency>

<dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
</dependency>

    </dependencies>

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

</project>

Before adding the dependencies for security, it all worked well with persistence, and now this. What am I missing?

Usr
  • 2,628
  • 10
  • 51
  • 91
  • There are similar errors and solutions, probably some annotation missing https://stackoverflow.com/questions/42907553/field-required-a-bean-of-type-that-could-not-be-found-error-spring-restful-ap – Dmitri Algazin Mar 14 '19 at 11:36
  • and check your Application has necessary annotations like @SpringBootApplication and @ComponentScan("com.example.*") – Dmitri Algazin Mar 14 '19 at 11:38
  • Show your class with @EnableAuthorizationServer, that the class throw that exception. But you linked different classes. – SAP Mar 15 '19 at 00:16

2 Answers2

4

I had the same problem as you.

That's how I solved it.

@Configuration
@EnableAuthorizationServer  //Open the authentication Server
public class CoreqiAuthorizationServerConfig implements AuthorizationServerConfigurer {
}

It only needs implements AuthorizationServerConfigurer

bummi
  • 27,123
  • 14
  • 62
  • 101
fanqi
  • 41
  • 1
4

Change your OAuth2 dependency with this:

<dependency>
    <groupId>org.springframework.security.oauth.boot</groupId>
    <artifactId>spring-security-oauth2-autoconfigure</artifactId>
    <version>2.1.6.RELEASE</version>
</dependency>
Giorgi Tsiklauri
  • 9,715
  • 8
  • 45
  • 66