考虑在配置中定义类型为“ com.modern.converter.UserConverter”的bean

时间:2018-07-02 13:09:56

标签: java spring-boot

spring boot的新功能,如果问题不清楚,请您谅解! 我收到以下错误:


申请无法开始


说明:

com.modern.services.UserService中的字段userConv需要一个类型为'com.modern.converter.UserConverter'的bean。

操作:

考虑在您的配置中定义类型为'com.modern.converter.UserConverter'的bean。

    package com.modern;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;



@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan 
@Configuration

public class SpringBootAngular4Application{


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

UserConverter

    package com.modern.converter;

import java.util.ArrayList;
import java.util.List;
import com.modern.module.User;
import com.modern.viewmodels.UserViewModel;


public class UserConverter implements IModelViewModelConverter < User , UserViewModel > {      

    @Override 
    public User fromViewModel ( UserViewModel vm ) { return null; }

    @Override 
    public List < User > fromViewModelList ( List < UserViewModel > vmList ) { return null ; }

    @Override 
    public UserViewModel toViewModel ( User m ) { 

        UserViewModel uvm = new UserViewModel();

        uvm.setFirstname ( m.getFirstname ()); 
        uvm.setLastname ( m.getLastname ()); 
        uvm.setCountry ( m.getCountry ()); 
        uvm.setAge ( m.getAge ());
        return uvm ; 

        }

     @Override 
     public List < UserViewModel > toViewModelList ( List < User > mList ) 
     {
         List < UserViewModel > users = new ArrayList <> (); for ( User u : mList ) 
             users . add ( this . toViewModel ( u ));  
         return users ; 
         }

}

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>

    <groupId>com.Devops</groupId>
    <artifactId>SpringBootAngular4</artifactId>
    <version>0.0.1 SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>SpringBootAngular4</name>
    <description>Demo project for Spring Boot with angularJS4</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.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-data-mongodb</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </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>

结构

Packges

0 个答案:

没有答案