@Service
public class AvailablePolicyService {
@Autowired
private var availablePolicyRepository : AvailablePolicyRepository = **AvailablePolicyRepository()**
fun saveAvailablePolicy(availablePolicy: AvailablePolicy): AvailablePolicy { return availablePolicyRepository.save(availablePolicy) }
fun getAllAvailablePolicy(): List<AvailablePolicy>{ return availablePolicyRepository.findAll() }
fun getAvailablePolicyByPolicyId(policyId: String?): AvailablePolicy? {
var availablePolicies: List<AvailablePolicy> = getAllAvailablePolicy()
for (availablePolicy in availablePolicies) {
if (availablePolicy.getPolicyId().equals(policyId)) {
return availablePolicy
}
}
return null
}
fun getAvailablePolicyByPolicyCategory(policyCategory: String?): ArrayList<AvailablePolicy> {
var availablePolicies: List<AvailablePolicy> = getAllAvailablePolicy()
var availablePolicyCategory = ArrayList<AvailablePolicy>()
for (availablePolicy in availablePolicies) {
if (availablePolicy.getPolicyCategory().equals(policyCategory)) {
availablePolicyCategory.add(availablePolicy)
}
}
return availablePolicyCategory
}
}
@Repository
interface AvailablePolicyRepository : MongoRepository<AvailablePolicy, String>
粗体文本显示了错误显示的位置,它是"Interface AvailablePolicyRepository does not have constructors"。如何从服务初始化存储库?
如何从服务初始化存储库?
问题就在这里。你不!Spring为您做:
@Autowired
private lateinit var availablePolicyRepository: AvailablePolicyRepository
字段注入已经过时了,你应该考虑使用构造函数注入。
@Service
class AvailablePolicyService(private val availablePolicyRepository: AvailablePolicyRepository) {...}