【发布时间】:2015-10-27 16:21:21
【问题描述】:
我有这个问题:
我用一些新代码解决了问题,制作了 StudentDeleteRepository.java 和 StudentDeleteRepositoryImpl.java 并按照用户的建议添加了标签:
@Autowired
private StudentDeleteRepository studentDeleteRepository;
@Transactional
public Student delete(Student student) {
return studentDeleteRepository.save(student);
}
StudentDeleteRepository.java 给出错误:
org.springframework.beans.factory.BeanCreationException:创建名为“studentDeleteController”的bean时出错:注入自动装配的依赖项失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:无法自动装配字段:私有 com.github.elizabetht.service.StudentDeleteService com.github.elizabetht.controller.StudentDeleteController.studentDeleteService;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为“studentDeleteService”的 bean 时出错:注入自动装配的依赖项失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:无法自动装配字段:私有 com.github.elizabetht.repository.StudentDeleteRepository com.github.elizabetht.service.StudentDeleteServiceImpl.studentDeleteRepository;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为“studentDeleteRepository”的 bean 时出错:FactoryBean 在创建对象时抛出异常;嵌套异常是 java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: 意外令牌:从第 1 行附近的第 10 列 [delete s from com.github.elizabetht.model.Student s where s.userName = :userName 和 s.password = :password]
这里是类StudentDeleteRepositoryImpl.java:
package com.github.elizabetht.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import com.github.elizabetht.model.Student;
@Repository("studentDeleteRepository")
public interface StudentDeleteRepository extends JpaRepository<Student, Long> {
@Query("delete s from Student s where s.userName = :userName and s.password = :password")
Student deleteByLogin(@Param("userName") String userName, @Param("password") String password);
}
【问题讨论】:
标签: java spring spring-mvc jpa orm