2017-10-05 116 views
0

的豆試圖運行我的春節,啓動應用程序時,我收到錯誤:春季啓動 - 考慮定義類型

場studentMapper在com.adam.rest.client.impl.StudentClientImpl 需要「'com.adam.rest.mapper.StudentMapper',找不到 。

你能提出什麼問題嗎? (參見下面的文件)

App.java

package com.adam.rest; 

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

@SpringBootApplication 
public class App { 

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

StudentClientImpl.java

package com.adam.rest.client.impl; 

import com.adam.rest.mapper.StudentMapper; 
import com.adam.rest.model.Student; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Repository; 

import java.util.Collection; 
import java.util.HashMap; 
import java.util.Map; 

@Repository 
public class StudentClientImpl { 

    @Autowired 
    private StudentMapper studentMapper; 

    private static Map<Integer, Student> students; 
     // DUMMY DATA GOES HERE 

    Collection<Student> getStudents() { return this.students.values(); } 

    Student getStudent(Integer id) { return this.students.get(id); } 

    ... 

StudentMapper.java

package com.adam.rest.mapper; 

import com.adam.rest.model.Student; 

import java.util.Collection; 

public interface StudentMapper { 

    Collection<Student> getStudents(); 

    Student getStudent(Integer id); 

    Student getStudent(String name); 

    void updateStudent(Student student); 

    void removeStudent(Integer id); 

    void removeStudent(String name); 

    void createStudent(Student student); 

} 
+0

難道你想實現'StudentMapper.java'在一些'@ Bean'實施 – Sridhar

+0

哪裏是你的界面'StudentMapper'的實施? – Jesper

回答

0

您接口創建一個實現類:

public class StudentMapperImpl implements StudentMapper { 
... 
} 

然後添加一個@Bean方法您@SpringBootApplication類或者其他類@Configuration。

例如:

@SpringBootApplication 
public class App { 

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

    @Bean 
    public StudentMapperImpl studentMapper() { 
     return new StudentMapperImpl(); 
    } 
}