gpt4 book ai didi

java - 异常 : No property delete found for type void in Spring Data JPA

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:12:10 24 4
gpt4 key购买 nike

我正在使用 Spring Data Jpa 并在部署项目时遇到异常我在服务和 serviceImpl 类中使用了 findAll() 方法,但收到异常,这是我的来源:

型号:

@Entity
@Table(name="CITY")
public class City {

@Id
@Column(name="ID", nullable = false, unique = true)
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;

@Column(name = "NAME")
private String name;
// get, set method
}

存储库类:

public interface CityJpaRepositoryCustom extends JpaRepository<City, Integer> { 
}

服务类:

public interface CityService {
public List<City> findAll();
}

ServiceImpl 类:

@Service
public class CityServiceImpl implements CityService {

@Resource
private CityJpaRepositoryCustom cityRepository;

@Override
@Transactional
public List<City> findAll() {
// TODO Auto-generated method stub
return cityRepository.findAll();
}
}

Controller 类:

@Controller
public class CityController {

@Autowired
private CityService cityService;

@RequestMapping(value="/list", method=RequestMethod.GET)
public ModelAndView getListCity(HttpServletRequest request,
HttpServletResponse response,
ModelMap model) {
ModelAndView mav = new ModelAndView("manageCity");

List<City> cityList = cityService.findAll();
mav.addObject("cityList", cityList);

return mav;
}

Pom.xml:

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.0.1.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<artifactId>hibernate-entitymanager</artifactId>
<groupId>org.hibernate</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<!-- SOLR -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>${spring-data-solr.verion}</version>
</dependency>

<!-- JSON -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.11</version>
</dependency>

<!-- WEB -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>

<!-- Hibernate 4 dependencies -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>${hibernate.version}</version>
</dependency>

</dependencies>

日志消息:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cityJpaRepositoryCustom': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property delete found for type void!
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)

我找到了一些相同的主题,但对我来说效果不佳,如何解决此异常?非常感谢!

最佳答案

将您的 Spring Boot 版本升级到最新版本 (1.5.1.RELEASE)。

您使用的是旧版本,而该版本又会引入可能不支持删除的旧版本 Spring Data。

关于java - 异常 : No property delete found for type void in Spring Data JPA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42701614/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com