내 Spring 어플리케이션 컨텍스트로 Hibernate를 연결하려고 시도하고있다. 나는 successfulyl SessionFactory에를 배선하고,하지만 난 getCurrentSession를 호출하려고 할 때 다음과 같은 오류를 참조하십시오Spring과 함께 사용되는 Hibernate sessionFactory.getCurrentSession()
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean$TransactionAwareInvocationHandler.invoke(AbstractSessionFactoryBean.java:270)
at $Proxy8.getCurrentSession(Unknown Source)
at org.company.web.ws.sample.impl.CheckSecurityImpl.verify(CheckSecurityImpl.java:31)
at org.company.web.ws.sample.impl.CheckSecurityImplTest.testCheckSecurity(CheckSecurityImplTest.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
나는 소스 세션 공장과 트랜잭션 관리자를 구성하고있다. 또한 트랜잭션 처리가 주석이 여기에
구동됩니다 지정한 나의 상황에 맞는 XML :@WebService(endpointInterface = "org.example.web.ws.sample.CheckSecurity")
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
public class CheckSecurityImpl implements CheckSecurity {
@Autowired
private SessionFactory sessionFactory;
@Transactional
public CheckSecurityResponse verify(String propertyValue, String propertyType) {
Session session = sessionFactory.getCurrentSession();
}
}
:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:mem:murex" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="classpath:/db-schema.sql"/>
<jdbc:script location="classpath:/db-testdata.sql"/>
</jdbc:initialize-database>
<!-- Hibernate Session Factory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>/security.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</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>
<tx:annotation-driven/>
<bean id="checkSecurityService" class="org.example.web.ws.sample.impl.CheckSecurityImpl" />
다음
내가 오류를 seeign 오전 클래스
이것이라고 할 때 sessionFactory는 null이 아니며 위의 오류가있는 오류입니다. openSession을 사용하면 모든 것이 정상적으로 작동하지만 트랜잭션과 함께 작동하지 않는다는 것을 이해합니다.
아이디어가 있으십니까? 감사합니다
최대 절전 모드 3 또는 4? – ElderMael
http://stackoverflow.com/questions/4961636/no-hibernate-session-bound-to-thread-and-configuration-does-not-allow-creation, 도움이 될 수 있습니다. – invariant
autowiring 처리는 무엇입니까? 컨텍스트.xml에 구성 요소 검사 또는 주석 구성이 표시되지 않습니다. 이것은 다른 맥락에서입니까? – MarkOfHall