我收到此错误:
com.example.service.Demoservice 中的字段 urs 需要一个无法找到的类型为“com.example.Resources.UserRepository”的 bean。
你能帮忙吗
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import com.example.Resources.UserRepository;
@SpringBootApplication
@ComponentScan("com.example")
@EnableJpaRepositories("com.example")
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
System.out.println("Started");
}
}
UserRepository.java 包 com.example.Resources;
import java.util.HashMap;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import com.example.model.DemoModel;
@Repository
public interface UserRepository extends JpaRepository<DemoModel,Integer> {
void save(HashMap<String, DemoModel> data);
}
演示服务.java
package com.example.service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import com.example.Resources.UserRepository;
import com.example.model.DemoModel;
@Component
public class Demoservice
{@Qualifier("UserRepository")
@Autowired
UserRepository urs;
HashMap<String,DemoModel> hash=new HashMap<>();
{
DemoModel dm=new DemoModel();
dm.setId(20);
dm.setName("Priya");
dm.setDept("cse");
hash.put("1", dm);
DemoModel demo=new DemoModel();
demo.setId(26);
demo.setName("Vijaya");
demo.setDept("IT");
hash.put("2", demo);
}
public HashMap<String, DemoModel> getAll()
{
return hash;
}
HUX布斯
相关分类