Java 带注释的Spring+Hibernate:如何将Hibernate会话绑定到线程?

Java 带注释的Spring+Hibernate:如何将Hibernate会话绑定到线程?,java,spring,hibernate,sessionfactory,Java,Spring,Hibernate,Sessionfactory,我是Spring新手,我正在尝试创建一个使用ApacheTomcat7、SQLServer、SpringMVC和Hibernate3的登录页面。我得到的错误是: message Request processing failed; nested exception is org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation

我是Spring新手,我正在尝试创建一个使用ApacheTomcat7、SQLServer、SpringMVC和Hibernate3的登录页面。我得到的错误是:

message Request processing failed; nested exception is org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause

org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
    org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
    org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:687)
    com.accumed.protracking.repository.JpaUserInfoRepository.get(JpaUserInfoRepository.java:38)
    com.accumed.protracking.service.UserInfoServiceImpl.login(UserInfoServiceImpl.java:20)
    com.accumed.protracking.LoginController.loginAttempt(LoginController.java:36)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
下面是我关心的类/配置文件:

我的存储库:

package com.accumed.protracking.repository;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
//import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.accumed.protracking.domain.UserInfo;

@Repository("userInfoRepository")
@Transactional
public class JpaUserInfoRepository implements UserInfoRepository {

    // @Autowired
    // private SessionFactory sessionFactory;

    private SessionFactory sessionFactory;  

    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    @Resource(name="sessionFactory")
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @Override   
    @Transactional(readOnly = true)
    public UserInfo get(String domain, String username, String password) {

        Session session = sessionFactory.getCurrentSession();

        Query query = session.getNamedQuery("callUserInfoGetProcedure")
                .setParameter("domain", domain)
                .setParameter("username", username)
                .setParameter("password", password);

        List result = query.list();

        if(result.size() > 0)
            return (UserInfo) result.get(0);

        return null;
    }

}
@Autowired
private SessionFactory sessionFactory;

public void setSessionFactory(SessionFactory sessionFactory) {
    this.sessionFactory = sessionFactory
}
我的实体:

package com.accumed.protracking.domain;

import static javax.persistence.GenerationType.IDENTITY; 

import javax.persistence.*;

import org.hibernate.validator.constraints.NotEmpty;

@NamedNativeQueries({
    @NamedNativeQuery(
    name = "callUserInfoGetProcedure",
    query = "exec UserInfoGet :domain, :username, :password",
    resultClass = UserInfo.class
    )
})

@Entity
@Table(name = "userInfo")
public class UserInfo {

    @NotEmpty
    private String domainName;
    @NotEmpty
    private Boolean corpActive;
    @NotEmpty
    private int tblCorporation_Id;
    @Id
    @NotEmpty
    private int tblUser_Id;
    @NotEmpty
    private Boolean active;
    @NotEmpty
    private int admin;
    @NotEmpty
    private String username;
    @NotEmpty
    private Boolean ForcePasswordUpdate;
    @NotEmpty
    private String nameFirst;
    @NotEmpty
    private String nameLast;
    @NotEmpty
    private int use_PT_CO_Ind;
    @NotEmpty
    private int serviceLevel;

    @Column(name = "DomainName")
    public String getDomainName() {
        return domainName;
    }
    public void setDomainName(String domainName) {
        this.domainName = domainName;
    }

    @Column(name = "CorpActive")
    public Boolean getCorpActive() {
        return corpActive;
    }
    public void setCorpActive(Boolean corpActive) {
        this.corpActive = corpActive;
    }

    @Column(name = "tblCorporation_Id")
    public int getTblCorporation_Id() {
        return tblCorporation_Id;
    }
    public void setTblCorporation_Id(int tblCorporation_Id) {
        this.tblCorporation_Id = tblCorporation_Id;
    }

    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "tblUser_Id")
    public int getUserId() {
        return tblUser_Id;
    }
    public void setUserId(int tblUser_Id) {
        this.tblUser_Id = tblUser_Id;
    }

    @Column(name = "Active")
    public Boolean getActive() {
        return active;
    }
    public void setActive(Boolean active) {
        this.active = active;
    }

    @Column(name = "admin")
    public int getAdmin() {
        return admin;
    }
    public void setAdmin(int admin) {
        this.admin = admin;
    }

    @Column(name = "User_Id")
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }

    @Column(name = "ForcePasswordUpdate")
    public Boolean getForcePasswordUpdate() {
        return ForcePasswordUpdate;
    }
    public void setForcePasswordUpdate(Boolean forcePasswordUpdate) {
        ForcePasswordUpdate = forcePasswordUpdate;
    }

    @Column(name = "NameFirst")
    public String getFirstName() {
        return nameFirst;
    }
    public void setNameFirst(String nameFirst) {
        this.nameFirst = nameFirst;
    }

    @Column(name = "NameLast")
    public String getLastName() {
        return nameLast;
    }
    public void setLastName(String nameLast) {
        this.nameLast = nameLast;
    }

    @Column(name = "Use_PT_CO_Ind")
    public int getUse_PT_CO_Ind() {
        return use_PT_CO_Ind;
    }
    public void setUse_PT_CO_Ind(int use_PT_CO_Ind) {
        this.use_PT_CO_Ind = use_PT_CO_Ind;
    }

    @Column(name = "getServiceLevel")
    public int getServiceLevel() {
        return serviceLevel;
    }
    public void setServiceLevel(int serviceLevel) {
        this.serviceLevel = serviceLevel;
    }

}
服务:

package com.accumed.protracking.service;

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

import com.accumed.protracking.domain.UserInfo;
import com.accumed.protracking.repository.UserInfoRepository;

@Service("userInfoService")
@Transactional
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoRepository userInfoRepository;

    @Override
    public UserInfo login(String domain, String username, String password)
            throws AuthenticationException {
        UserInfo userInfo = this.userInfoRepository.get(domain, username, password);
        if (userInfo == null) {
            throw new AuthenticationException("Wrong domain/username/password combination.", "invalid.username");
        }

        return userInfo;
    }
}
控制器:

package com.accumed.protracking;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.accumed.protracking.domain.UserInfo;
import com.accumed.protracking.service.AuthenticationException;
import com.accumed.protracking.service.UserInfoService;

@Controller
@RequestMapping(value = "/login")
public class LoginController {

    public static final String ACCOUNT_ATTRIBUTE = "account";

    @Autowired
    private UserInfoService userInfoService;

    @RequestMapping(method = RequestMethod.GET)
    public String initial()
    {
        return "login";
    }

    @RequestMapping(method = RequestMethod.POST)
    public String loginAttempt(@RequestParam String domain, @RequestParam String username, @RequestParam String password,
            RedirectAttributes redirect, HttpSession session) throws AuthenticationException { 

        try {
            UserInfo userInfo = this.userInfoService.login(domain, username, password);
            session.setAttribute(ACCOUNT_ATTRIBUTE, userInfo);
            return "redirect:/index.htm";
        } catch (AuthenticationException ae) {
            redirect.addFlashAttribute("exception", ae);
            return "redirect:/login";
        }
    }
}
web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>
my root-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    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"
    xsi:schemaLocation="
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <!-- Root Context: defines shared resources visible to all other web components -->
    <context:component-scan base-package="com.accumed.protracking.service"/>

    <tx:annotation-driven/>

    <context:component-scan base-package="com.accumed.protracking.repository" />

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
        <property name="url" value="jdbc:sqlserver:***********;databaseName=***********"/>
        <property name="username" value="***********"/>
        <property name="password" value="***********"/>
    </bean>    

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="packagesToScan" value="com.accumed.protracking.domain"/>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
                <prop key="hibernate.max_fetch_depth">3</prop>
                <prop key="hibernate.jdbc.fetch_size">50</prop>
                <prop key="hibernate.jdbc.batch_size">10</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>        
    </bean>    

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

    <context:component-scan base-package="com.accumed.protracking" />   

</beans:beans>
My servlet-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    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"
    xsi:schemaLocation="
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <!-- Root Context: defines shared resources visible to all other web components -->
    <context:component-scan base-package="com.accumed.protracking.service"/>

    <tx:annotation-driven/>

    <context:component-scan base-package="com.accumed.protracking.repository" />

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
        <property name="url" value="jdbc:sqlserver:***********;databaseName=***********"/>
        <property name="username" value="***********"/>
        <property name="password" value="***********"/>
    </bean>    

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="packagesToScan" value="com.accumed.protracking.domain"/>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
                <prop key="hibernate.max_fetch_depth">3</prop>
                <prop key="hibernate.jdbc.fetch_size">50</prop>
                <prop key="hibernate.jdbc.batch_size">10</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>        
    </bean>    

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

    <context:component-scan base-package="com.accumed.protracking" />   

</beans:beans>

如果没有服务层,则将@Transactional添加到服务或控制器的适当方法中

如果没有服务层,则将@Transactional添加到服务或控制器的适当方法中

看起来您的存储库/服务缺少启动事务的功能

您可以将其放在您的类或每个方法上,具体取决于您希望如何做

@Transactional(readOnly = true)
您的save方法将readOnly设置为false

然后在spring应用程序上下文中定义以下内容

<context:component-scan base-package="com.accumed.protracking.service" /> 
<tx:annotation-driven />

您的存储库/服务似乎缺少启动事务的功能

您可以将其放在您的类或每个方法上,具体取决于您希望如何做

@Transactional(readOnly = true)
您的save方法将readOnly设置为false

然后在spring应用程序上下文中定义以下内容

<context:component-scan base-package="com.accumed.protracking.service" /> 
<tx:annotation-driven />

您的存储库类似乎与注入到服务AccountRepository和UserInfoRepository中的类不匹配,但我怀疑问题在于您没有注入对Hibernate会话工厂的引用。尝试将其添加到您的存储库:

package com.accumed.protracking.repository;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
//import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.accumed.protracking.domain.UserInfo;

@Repository("userInfoRepository")
@Transactional
public class JpaUserInfoRepository implements UserInfoRepository {

    // @Autowired
    // private SessionFactory sessionFactory;

    private SessionFactory sessionFactory;  

    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    @Resource(name="sessionFactory")
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @Override   
    @Transactional(readOnly = true)
    public UserInfo get(String domain, String username, String password) {

        Session session = sessionFactory.getCurrentSession();

        Query query = session.getNamedQuery("callUserInfoGetProcedure")
                .setParameter("domain", domain)
                .setParameter("username", username)
                .setParameter("password", password);

        List result = query.list();

        if(result.size() > 0)
            return (UserInfo) result.get(0);

        return null;
    }

}
@Autowired
private SessionFactory sessionFactory;

public void setSessionFactory(SessionFactory sessionFactory) {
    this.sessionFactory = sessionFactory
}

Reference:。

您的存储库类似乎与注入到您的服务AccountRepository和UserInfoRepository中的类不匹配-但我怀疑问题在于您没有注入对Hibernate会话工厂的引用。尝试将其添加到您的存储库:

package com.accumed.protracking.repository;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
//import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.accumed.protracking.domain.UserInfo;

@Repository("userInfoRepository")
@Transactional
public class JpaUserInfoRepository implements UserInfoRepository {

    // @Autowired
    // private SessionFactory sessionFactory;

    private SessionFactory sessionFactory;  

    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    @Resource(name="sessionFactory")
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @Override   
    @Transactional(readOnly = true)
    public UserInfo get(String domain, String username, String password) {

        Session session = sessionFactory.getCurrentSession();

        Query query = session.getNamedQuery("callUserInfoGetProcedure")
                .setParameter("domain", domain)
                .setParameter("username", username)
                .setParameter("password", password);

        List result = query.list();

        if(result.size() > 0)
            return (UserInfo) result.get(0);

        return null;
    }

}
@Autowired
private SessionFactory sessionFactory;

public void setSessionFactory(SessionFactory sessionFactory) {
    this.sessionFactory = sessionFactory
}

参考:。

我认为spring应用程序上下文是root-context.xml文件?我目前在web.xml和root-context.xml中都没有tx名称空间,tx名称空间的url是什么?好的,我找到了这个:xmlns:tx=并添加了它,以及您向root-context.xml建议的上下文和tx行,我得到了相同的错误。好的,我已经更新了root-context.xml,我仍然得到相同的错误。还有什么想法和/或建议吗?在执行tx:annotation-driven之前,能否更新根上下文以对服务层进行组件扫描。好的,我在tx:annotation驱动之前添加了组件扫描。我在结尾试过,然后在开头试过。我在tx:annotation-driven前后使用com.accumed.protracking.repository进行了尝试,但似乎没有任何效果。我已将root-context.xml更新为我的最新配置。我认为spring应用程序上下文是root-context.xml文件?我目前在web.xml和root-context.xml中都没有tx名称空间,tx名称空间的url是什么?好的,我找到了这个:xmlns:tx=并添加了它,以及您向root-context.xml建议的上下文和tx行,我得到了相同的错误。好的,我已经更新了root-context.xml,我仍然得到相同的错误。还有什么想法和/或建议吗?在执行tx:annotation-driven之前,能否更新根上下文以对服务层进行组件扫描。好的,我在tx:annotation驱动之前添加了组件扫描。我在结尾试过,然后在开头试过。我在tx:annotation-driven前后使用com.accumed.protracking.repository进行了尝试,但似乎没有任何效果。我已将root-context.xml更新为我的最新配置。JpaUserInfoRepository由UserInfoServiceImpl使用,但我没有看到您发布任何具有该名称的类,只有JPAACConRepository。可能是你把这两件事搞混了吗?如果没有,那么您应该发布jpauserniforepository.yair,感谢您指出这一点。我刚刚将所有代码更新为我目前拥有的代码。我确实使用了错误的服务,我现在发布了正确的服务。JpaUserInfoRepository由UserInfoServiceImpl使用,但我没有看到您发布任何具有该名称的类,只有JPAACConRepository。可能是你把这两件事搞混了吗?如果没有,那么您应该发布jpauserniforepository.yair,感谢您指出这一点。我刚刚将所有代码更新为我目前拥有的代码。我确实有错误的服务,我现在发布了正确的服务。我开始查看文档,并试图通过配置而不是属性化方法来运行它。我从存储库中删除了所有属性,然后将其添加到root-context.xml,Tomcat现在不会运行。任何想法:@SamCarleton您还应该从jpauserniforepository.setSessionFactory中删除@Resource,因为引用只能以一种方式定义:注释或xml。我开始查看文档,并尝试通过配置而不是属性化方法来运行它。我从存储库中删除了所有属性,然后将其添加到
root-context.xml,Tomcat现在不会运行。任何想法:@SamCarleton您还应该从jpauserniforepository.setSessionFactory中删除@Resource,因为引用只能以一种方式定义:注释或xml。