程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了无法自动装配存储库服务Spring JPA大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决无法自动装配存储库服务Spring JPA?

开发过程中遇到无法自动装配存储库服务Spring JPA的问题如何解决?下面主要结合日常开发的经验,给出你关于无法自动装配存储库服务Spring JPA的解决方法建议,希望对你解决无法自动装配存储库服务Spring JPA有所启发或帮助;

@Repository 丢失了,请尝试在仓库的接口上方添加并删除Spring不允许的bean声明。

解决方法

我正在尝试在代码中使用用户存储库,但是intellij给了我错误。

interface is not allowed for non abstract beans

我有以下设置。

@Entity
public class User {

    @Id
    private long id;
    private String firstName;
    private String lastName;
    private String profileUrl;
    private String email;
    private String LOCATIOn;

    protected User(){};

    public User(String first,String last,String profileUrl,String email,String LOCATIOn){
        this.firstName = first;
        this.lastName = last;
        this.profileUrl = profileUrl;
        this.email = email;
        this.LOCATIOn = LOCATIOn;

    }

    public User(Person person){
        this.firstName = person.getName().getGivenName();
        this.lastName = person.getName().getFamilyName();
        this.profileUrl = person.getImage().getUrl();
        this.email = person.getEmails().get(0).getValue();
        this.LOCATIOn = person.getCurrentLOCATIOn();
    }
}


public interface UserRepository extends CrudRepository<User,Long> {

    List<User> findByProfilEID(long id);
}

我试图用@service@Repository但无济于事。

@Component
public class UserRepositoryImpl {

    @Autowired
    private UserRepository userRepository;


    public void doSomething() {
        List<User> byProfilEID = userRepository.findByProfilEID(100);
    }
}

XML格式

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/scheR_562_11845@a/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLscheR_562_11845@a-instance"
       xmlns:tx="http://www.springframework.org/scheR_562_11845@a/tx"
       xmlns:context="http://www.springframework.org/scheR_562_11845@a/context"
       xmlns:rep="http://www.springframework.org/scheR_562_11845@a/data/jpa"
       xsi:scheR_562_11845@aLOCATIOn="http://www.springframework.org/scheR_562_11845@a/beans
     http://www.springframework.org/scheR_562_11845@a/beans/spring-beans.xsd 
     http://www.springframework.org/scheR_562_11845@a/tx
     http://www.springframework.org/scheR_562_11845@a/tx/spring-tx-3.0.xsd
     http://www.springframework.org/scheR_562_11845@a/data/jpa
     http://www.springframework.org/scheR_562_11845@a/data/jpa/spring-jpa.xsd
       http://www.springframework.org/scheR_562_11845@a/context http://www.springframework.org/scheR_562_11845@a/context/spring-context.xsd">

    <rep:repositories base-package="com.planit.persistence.*"/>
    <bean id="userRepository" class="com.planit.persistence.registration.UserRepository"/>

    <!-- DB CONNECTION-->
    <bean class="java.net.URI" id="dbUrl">
        <constructor-arg value="#{T(com.ProjectUtils).getDBUrl()}"/>
    </bean>

    <bean id="datasource" class="org.springframework.jdbc.datasource.DriveRMANagerDatasource">
        <property name="driverClassName" value="org.POSTGResql.Driver"/>
        <property name="url"
                  value="#{ 'jdbc:POSTGResql://' + @dbUrl.getHost() + ':' + @dbUrl.getPort() + @dbUrl.getPath() }"/>
        <property name="username" value="#{ @dbUrl.getUserInfo().split(':')[0] }"/>
        <property name="password" value="#{ @dbUrl.getUserInfo().split(':')[1] }"/>
    </bean>


    <bean id="myEmf"
          class="org.springframework.orm.jpa.LocalContainerEntitymanagerFactoryBean">
        <property name="datasource" ref="datasource"/>
        <property name="packagesToScan" value="com.planit.persistence"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true"/>
                <property name="generateDdl" value="true"/>
                <property name="database" value="POSTGRESQL"/>
            </bean>
        </property>
    </bean>

    <bean id="txManager" class="org.springframework.orm.jpa.JpatransactionManager">
        <property name="entitymanagerFactory" ref="myEmf"/>
    </bean>

    <tx:Annotation-driven transaction-manager="txManager"/>    
</beans>

我在定义userRepositorybean的spring.xml行中发生错误。

提前致谢。

大佬总结

以上是大佬教程为你收集整理的无法自动装配存储库服务Spring JPA全部内容,希望文章能够帮你解决无法自动装配存储库服务Spring JPA所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。