I am facing an issue while calling the service first time it's thrown error org.springframework.dao.TransientDataAccessResourceException: SqlSessionFactory must be using a SpringManagedTransactionFactory in order to use Spring transaction synchronizationsecond time the data retrieve successfully.
UserServiceEJB.java
#Stateless(name = "UserService")
#Interceptors
#Transactional
#TransactionAttribute(TransactionAttributeType.REQUIRED)
#Local(UserService.class)
public class UserServiceEJB implements UserService {
public UsersDetailsPojo[] getUsersList(UserRequest userRequest) {
return getUsers(userRequest);
}
}
config.xml
<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:jee="http://www.springframework.org/schema/jee"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:c="http://www.springframework.org/schema/c"
xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.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">
<!-- MyBatis SqlSessionFactory -->
<bean id="mybatisTransactionManager" class="org.apache.ibatis.transaction.managed.ManagedTransactionFactory" />
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate" c:_0-ref="sqlSessionFactory" />
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref="dataSource" p:configLocation="classpath:mybatis-config.xml"
p:transactionFactory-ref="mybatisTransactionManager" />
Getting below error
org.springframework.dao.TransientDataAccessResourceException: SqlSessionFactory must be using a SpringManagedTransactionFactory in order to use Spring transaction synchronization
at org.mybatis.spring.SqlSessionUtils.registerSessionHolder(SqlSessionUtils.java:142)
at org.mybatis.spring.SqlSessionUtils.getSqlSession(SqlSessionUtils.java:102)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:428)
at com.sun.proxy.$Proxy123.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)
Is there any suggestions? Please help.
Related
This is my system.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:amq="http://activemq.apache.org/schema/core"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<import resource="jetty.xml" />
<import resource="communication.xml" />
<camelContext xmlns="http://camel.apache.org/schema/spring"
id="camel">
<route>
<from uri="file://test.json"/>
<threads>
<bean ref="operationTest" method="test" />
</threads>
</route>
</camelContext>
</beans>
Here is my communication.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:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<bean id="operationTest" class="edu.test.Test">
</bean>
</beans>
I have a main of
context = new SpringServerContext(new FileSystemXmlApplicationContext("conf/system.xml"));
Runtime.getRuntime().addShutdownHook(new Thread(group, new Runnable() {
#Override
public void run() {
stop();
}
}, shutdownThreadName));
context.startup();
and the Test class has a method of
public Object test(Object info) {
//prints info
}
Yet when I run, nothing prints. . .
Can we not trigger the from tag by a file?
I am also trying from Active MQ and is not succeding getting an error of
because of No endpoint could be found for: brokerURL, please check your classpath contains the needed Camel component jar.
I used Active MQ for the route and it worked
my spring code is below. please any one explain what is wrong in my code.
TempImpl.class
#Component
#Transactional
public class tempImpl{
#Autowired
private TempController tempController;
public void temp_1(){
String status = tempController.saveTemp1();
}
}
TempController.class
#Component
public class TempController{
#Autowired
private TempDao tempDao;
public void saveTemp1(){
String status = tempDao.saveTemp1();
}
}
TempDao.class
#Component
public class TempDao{
public void saveTemp1(){
TempEntity tempEntity = new TempEntity();
tempEntity.seTemp1Value("hello");
}
}
xml config file is
<?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:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
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
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.temp.dao" />
<context:component-scan base-package="com.temp.service" />
<context:component-scan base-package="com.temp.controller" />
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
<bean id="transactionManager" class="org.springframework.transaction.jta.WebLogicJtaTransactionManager"/>
<!-- For Struts Action Class -->
<bean name="/saveTestAction" class="com.temp.tempAction" />
</beans>
when my code comes Dao class and while executing tempEntity.seTemp1Value("hello"); this line
No qualifying bean of type 'com.temp.dao.TempDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:
{#org.springframework.beans.factory.annotation.Autowired(required=true)}
I have a profiles.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:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="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
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<!-- Local -->
<beans profile="local">
<util:properties id="localProperties">
<prop key="property">localProperty</prop>
</util:properties>
<context:property-placeholder properties-ref="localProperties" ignore-unresolvable="true" />
</beans>
<!-- Dev -->
<beans profile="dev">
<util:properties id="devProperties">
<prop key="property">devProperty</prop>
</util:properties>
<context:property-placeholder properties-ref="devProperties" ignore-unresolvable="true" />
</beans>
</beans>
and I have a org.springframework.ws.client.support.interceptor.ClientInterceptor that I want to use values from profiles.xml:
#Component
public class HeaderInjector implements ClientInterceptor {
#Value("${property}")
private static String someProperty;
#Override
public boolean handleRequest(MessageContext messageContext)
throws WebServiceClientException {
//want to use someProperty here based on value from profiles.xml
}
}
How can I do this? I tried adding #ImportResource("profiles.xml") at the top of the class like
#Component
#ImportResource("profiles.xml")
public class SoapLeadPipeHeaderInjector implements ClientInterceptor {
but someProperty never gets set.
First of all there is nothing about Spring Integration in your question, so be careful with choosing tags for questions.
#ImportResource("profiles.xml") can be applied on the #Configuration class if you start application context from annotations.
If your main entry point is XML configuration, your #Component must be scanned via <context:component-scan base-package="..."/> then.
See more info in the Spring Framework Reference Manual.
I've created a simple Spring-based web application, with a #RestController annotation for a class that one of its mappings returns a JSON response.
It works perfectly when I run it on localhost, but I get the following error when I try to call the url on the host it is deployed to (Bluemix). I got this exception on the localhost version, when I didn't define the class as #RestController (or it's parallel - #Controller & #ResponseBody):
'Exception thrown by application class 'org.springframework.web.servlet.view.InternalResourceView.prepareForRendering:205'
javax.servlet.ServletException: Circular view path [nextStep]: would dispatch back to the current handler URL [/nextStep] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)'
These are my definitions:
RestController
#Controller
#ResponseBody
public class InterviewRESTController {
#Autowired
private transient InterviewFlowLogic interviewFlowLogic;
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
#RequestMapping("/nextStep")
public ServiceRESTResponse nextStep(#RequestParam(value="name", defaultValue="World") String name){
return new ServiceRESTResponse(counter.incrementAndGet(),
String.format(template, name));
}
}
dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<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:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
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
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<context:component-scan base-package="il.intervyo.client.controller"></context:component-scan>
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager"/>
<bean id="contentNegotiationManager"
class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="defaultContentType" value="application/xml" />
<property name="mediaTypes">
<map>
<entry key="json" value="application/json" />
</map>
</property>
</bean>
</beans>
Again, it is important to stress out that this code works when I run it localhost and the url returns the Json format response, but fails only on the deployed version - I saw the few questions-and-answers that are already on the site, non of them refers to this specific issue.
I'd gladly supply with any additional info needed (pom.xml, web.xml, etc.)
i want to define an #Around aspect for a method of my #Entity
All my entities are in package data.entity
A define an aspect like this:
#Aspect
public class TestAspect {
#Around("execution(* data.entity..*(..))")
public Object aroundAdvice(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("INTERCEPT: "+pjp.toLongString());
return pjp.proceed();
}
}
But never is intercepted... where is my error?
In spring xml i have this:
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<context:component-scan base-package="data.dao, data.service" />
<tx:annotation-driven proxy-target-class="true"/>
<aop:aspectj-autoproxy/>
<bean id="testAspect" class="spring.TestAspect" />
... datasource and other ...
</beans>
I try also
#Around("target(data.entity.MyEntity)")
and
#Around("target(data.entity..)")
but still not work.
Thanks.
It looks like you use spring-proxy-aop. This works only if the class is a spring manged bean, and the adviced method must be invoked from an other object.
Try to use real aspectJ instead of spring-proxy-aop.
I have just started using AOP and below are the findings at my level
i am assuming you have necessary jar files, aspectjweaver-1.6.10.jar and org.springframework.aop-3.0.5.RELEASE.jar present in your apps classpath.
The method aroundAdvice, as you have defined currently is perfect.
Could you remove the below line and try.
<context:component-scan base-package="data.dao, data.service" />