我正在使用Spring Boot应用程序并使用MySQL和mongodb作为数据库。下面您可以看到MySQL的Spring Boot主应用程序。
@EnableFeignClients(basePackages = {"com.saman.kamal.nimalservice"})
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = {"com.saman.kamal.nimalservice"})
@EnableOAuth2Client
@EnableJpaRepositories(basePackages = {"com.saman.kamal.nimalservice.repository"})
@EntityScan(basePackages = {"com.saman.kamal.nimalservice.domain"})
public class HuththaApplication {
public static void main(String[] args) {
SpringApplication.run(HuththaApplication.class, args);
}
}
如果我使用mongodb代替mysql
@EntityScan(basePackages = {"com.saman.kamal.nimalservice.domain"})
应该改变。应该如何改变?
下面您可以看到我的实体类。
import java.io.Serializable;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Document
public class EbankLog implements Serializable {
private static final Long serialVersionUID = 1L;
@Id
private String bothala;
private String sapaththu;
private String sereppu;
private String kanda;
private String bag;
}
答案 0 :(得分:0)
您尚未让Spring知道您的MongoDb存储库在哪里。为此,请使用@EnableMongoRepositories
。参见以下代码:
@EnableMongoRepositories(basePackages = "your.mongodb.repositories.package")
@EnableFeignClients(basePackages = {"com.saman.kamal.nimalservice"})
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = {"com.saman.kamal.nimalservice"})
@EnableOAuth2Client
@EnableJpaRepositories(basePackages = {"com.saman.kamal.nimalservice.repository"})
@EntityScan(basePackages = {"com.saman.kamal.nimalservice.domain"})
public class HuththaApplication {
public static void main(String[] args) {
SpringApplication.run(HuththaApplication.class, args);
}
}