当前位置: 首页 > 知识库问答 >
问题:

无效的spring-jpa版本

端木冷勋
2023-03-14

在我的项目中,我有三个模型文件--用户、约会和通知。有三个存储库接口,每个接口实现CrudRepository。服务类和控制器类也存在。在执行项目时,我得到了两个错误:1。在类路径上未检测到spring Webinitializer。2.创建bean时出现异常。下面是堆栈跟踪:

INFO: No Spring WebApplicationInitializer types detected on classpath
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further     details.
Feb 14, 2018 8:54:00 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Feb 14, 2018 8:54:03 AM org.apache.catalina.core.StandardContext    listenerStart
SEVERE: Exception sending context initialized event to listener instance  of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating   bean with name 'EHealthController': Injection of autowired dependencies  failed; nested exception is    org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.cl3.service.EHealthService   com.cl3.controller.EHealthController.eservice; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'EHealthService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.cl3.model.UserRepository com.cl3.service.EHealthService.uRepo; nested exception is java.lang.NoSuchMethodError: org.springframework.beans.BeanUtils.findPropertyForMethod(Ljava/lang/reflect/Method;Ljava/lang/Class;)Ljava/beans/PropertyDescriptor;
<beans 
xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
 http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">


<context:component-scan base-package="com.cl3.controller" />
<context:component-scan base-package="com.cl3.model" />
<context:component-scan base-package="com.cl3.service" />

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/WEB-INF/pages/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>

<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <property name="showSql" value="true"/>
    <property name="generateDdl" value="true"/>
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>

    <property name="packagesToScan" value="com.cl3.model"/>
</bean>

 <bean id="transactionManager" 
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven/>

 <jpa:repositories base-package="com.cl3.model"/>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="org.postgresql.Driver" />
    <property name="url" value="jdbc:postgresql://localhost:5432/cl3" />
    <property name="username" value="ucan" />
    <property name="password" value="ucan" />
</bean>

<!-- <bean id="eservice" class="com.cl3.service.EHealthService">
    <property name="uRepo" ref="uRepo"></property>
    <property name="nRepo" ref="nRepo"></property>
    <property name="aRepo" ref="aRepo"></property>
</bean>

  <bean id="uRepo"  class="com.cl3.model.UserRepository">
</bean>
 <bean id="nRepo" class="com.cl3.model.NotificationRepository">
</bean>
<bean id="aRepo"  class="com.cl3.model.AppointmentRepository">
</bean> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.cl3</groupId>
 <artifactId>EHealth</artifactId>
 <packaging>war</packaging>
 <version>0.0.1-SNAPSHOT</version>
 <name>EHealth Maven Webapp</name>
 <url>http://maven.apache.org</url>

 <properties>
    <jdk.version>1.8</jdk.version>
    <spring.version>4.1.5.RELEASE</spring.version>
    <jstl.version>1.2</jstl.version>
    <junit.version>4.12</junit.version>
    <logback.version>1.0.13</logback.version>
    <jcl-over-slf4j.version>1.7.5</jcl-over-slf4j.version>      
    <hibernate.version>3.6.10.Final</hibernate.version>
</properties>


 <dependencies>
 <!-- https://mvnrepository.com/artifact/org.springframework.data /spring-data-jpa -->
  <dependency>
  <groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.6.4.RELEASE</version>
</dependency>

        <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.4.1207.jre7</version>
    </dependency>


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


     <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>3.6.10.Final</version>    
</dependency>

     <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>
     <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>1.4</version>
    </dependency>
  </dependencies>  
<build>
<finalName>EHealth</finalName>
<plugins>

        <!-- Set JDK Compiler Level -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
            </configuration>
        </plugin>

        <!-- For Tomcat -->
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <path>/EHealth</path>
            </configuration>
        </plugin>

    </plugins>

userrepository.class:包com.cl3.model;

导入java.util.List;

导入org.springframework.data.repository.crudrepository;导入org.springframework.stereoType.repository;

@Repository
public interface UserRepository extends CrudRepository<User, Long> 
{
List<User> findByemail(String email);
List<User> findByisdoctor(boolean status);
User findByid(long uid);
}
package com.cl3.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cl3.model.*;

@Service
public class EHealthService 
{
@Autowired
UserRepository uRepo;


@Autowired
AppointmentRepository aRepo;

@Autowired
NotificationRepository nRepo;


public void registerUser(User u)
{
    uRepo.save(u);
}


public boolean login(User u)
{
    if(uRepo.findByemail(u.getEmail())!=null)
        return true;
    else
        return false;
}

public List<User> getDoctorList()
{
    return uRepo.findByisdoctor(true);
}


public void deleteAppointment(long aid)
{
    Appointment a =aRepo.findByid(aid);
    a.setIscanceled(true);
    Notification n = new Notification();
    n.setAppointmentid(a);
    createNotification(n);

}

public void createNotification(Notification n)
{
    nRepo.save(n);
}


}

共有1个答案

于嘉许
2023-03-14

Spring Version-4.3.8。Release和Spring data jpa Version-1.0.2。Release组合对我来说很有效。

如果是版本问题,那么可能是您可以尝试这种组合。

 类似资料:
  • 在使用Spring Data JPA和Hibernate的web应用程序中,我们利用web分页功能在各种实体列表中提供分页和排序功能。 这允许在呈现的html中将实体属性定义为特殊的排序请求参数,其中值实际上与要排序的实体中的属性匹配。 这将生成一个结果URL,例如: 问题是,用户可能会修改URL以使用无效的属性,这些属性引用不存在的列/属性名称,或者更糟的是,使用无效的JPA查询字符导致无效语法

  • 我正在尝试使用以下命令构建我的Spring启动项目: 但它不断抛出这个错误: 我的项目使用Java版本11,IntelliJ Java版本也设置为11。 这是我到目前为止在IntelliJ上完成的Java版本设置: 当我跑完这一切后 我想我已经做了所有可能的事情。还有其他我可以尝试的设置吗??

  • 问题内容: 我见过类似的问题,但尚未找到答案。 使用Maven编译,我得到: 这是pom.xml: Javac版本: Java版本: 知道会是什么吗? 问题答案: 您需要将JAVA_HOME设置为jdk7主目录,例如在Microsoft Windows上: “ C:\ Program Files \ Java \ jdk1.7.0_40” 或在OS X上: /图书馆/Java/JavaVirtua

  • 我与Gradle在IntelliJ中创建了一个新的Java项目,该项目使用Java 17。运行我的应用程序时出现错误。 我的设置 我已经通过安装了,并将其设置为我的。 已设置为。 在

  • 使用maven compile,我得到: 下面是pom.xml: Javac版本: 知道可能是什么吗?