Below snippet is available in servlet.xml of Tomcat
<Resource name="jms/queue/NotificationQ"
auth="Container"
type="org.apache.activemq.command.ActiveMQQueue"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
physicalName="NotificationQ"/>
and in context.xml
<ResourceLink name="jms/queue/NotificationQ" global="jms/queue/NotificationQ"/>
Now I am in the process of creating a standalone war file using spring boot. How do I declare the jms queue in spring boot, so that the above configuration works with embedded tomcat?
Related
Hello everyone can someone explain me this lines of code thanks
<!-- websocket client bean -->
<bean id="webSocketClient" class="org.springframework.web.socket.client.standard.StandardWebSocketClient"/>
<!-- inbound-channel-adapter && client-container -->
<int-websocket:client-container id="clientContainer"
client="webSocketClient"
uri="wss://genericurl.com:9443/ws/>
i would understand how websocket client bean and container works togheter
I have an application deployed on WebLogic 12c (12.2.1.4) using Hibernate 5.2.18. Weblogic 12c doc references JPA 2.1 compatibility and Hibernate 5.3+ requires JPA 2.2. Can I prepend the JPA 2.2 API to my startup classpath and use Hibernate 5.3+ or should I stick with Hibernate 5.2 for the time being?
Yes, this configuration is possible.
To avoid conflicts with WebLogic built-in JPA capabilities you should do the following:
According to this
In a full Java EE environment, consider obtaining your EntityManagerFactory from JNDI. Alternatively, specify a custom persistenceXmlLocation on your LocalContainerEntityManagerFactoryBean definition (for example, META-INF/my-persistence.xml) and include only a descriptor with that name in your application jar files. Because the Java EE server looks only for default META-INF/persistence.xml files, it ignores such custom persistence units and, hence, avoids conflicts with a Spring-driven JPA setup upfront.
You can use something like this in the spring context config.
<?xml version="1.0" encoding="UTF-8"?>
<beans>
<!-- ... -->
<jee:jndi-lookup id="DS" jndi-name="appDS" />
<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath:META-INF/app-persistence.xml" />
<property name="dataSource" ref="DS" />
</bean>
<!-- ... -->
</beans>
According to this
To configure the FilteringClassLoader to specify that a certain package is loaded from an application, add a prefer-application-packages descriptor element to weblogic-application.xml which details the list of packages to be loaded from the application.
You should add the following snippet to your META-INF/weblogic-application.xml
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-application>
<prefer-application-packages>
<!-- ... -->
<package-name>javax.persistence.*</package-name>
</prefer-application-packages>
</weblogic-application>
I have a Spring Boot application which connects to different MySQL databases. I am planning to add connection pool support to this application. Does the Tomcat JDBC Connection Pool (default Spring boot pool) support more than one pool for each of my databases?
Not sure how this would be different under Spring Boot, but for standard web apps you can configure this at the webapp level, by adding in web.xml any number of the following:
<resource-ref>
<res-ref-name>jdbc/yourname</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
and in context.xml the corresponding number of the following:
<Resource name="jdbc/yourname" auth="Container" type="javax.sql.DataSource"
maxActive="30"
maxIdle="30"
maxWait="2000"
removeAbandoned="true"
...
I need to implement JTA transaction management using spring jdbc in liferay. I have two databases connected in liferay using jndi. In my project I am doing jdbc CRUD operation using jdbc spring dao and for liferay, it is through liferay build-in service api. For any exception, rollback is working fine for other db but it is not working for liferay.
Below is my code sample:
In portal-ext.prop I have defined
transaction.management.impl= <JTATransactionmanager>
In my project's context.xml of tomcat I have defined user transaction as mentioned at liferay's site :
context.xml
`<Resource name="UserTransaction" auth="Container" type="javax.transaction.UserTransaction" />
<Transaction factory="org.objectweb.jotm.UserTransactionFactory" jotm.timeout="600" /><br>
<Resource auth="Container" type="javax.sql.DataSource" factory="org.objectweb.jotm.datasource.DataSourceFactory" driverClassName="<postgresqldriver>" name="jdbc/LiferayPool" username="root" password="" url="jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false" />}}}<br>
<Resource auth="Container" type="javax.sql.DataSource" factory="org.objectweb.jotm.datasource.DataSourceFactory" driverClassName="<postgresqldriver>" name="jdbc/test" username="root" password="" url="jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false" />}}}
`
In bean.xml of my project :
<tx:annotation-driven transaction-manager="txManager"/>
<beans:bean id="dbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<beans:property name="jndiName" value="java:comp/env/jdbc/test"/>
</beans:bean>
<bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager" />
in my class:
#Transactional(rollback{myexception.class})
public void test()
first of all put an eye on this discussion.
What you wouldn't forget is that Liferay rollbacks both for PortalException or SystemException... but it rollbacks only the beans injected inside the current transaction context.
This means that you shouldn't use XLocalServiceUtil, but the injected xLocalService bean.
To get it you need to advice your service layer by service.xml declarations or, inside your serviceImpl class, by adding and referring to:
#BeanReference(type=XArticleLocalService.class)
protected XArticleLocalService xArticleLocalService;
I hope this can help you.
I believe you are using the XXXServiceUtil.java. Whenever you use ServiceUtil, any method you call executes under a different transaction manager (regardless of current thread transaction state) as it's a completely different class loader. Remember in Liferay, every portlet/plugin has its own class loader.
I am developing a spring web application . A JAR file which I use in my application , is looking for DataSource using JNDI. I configured the element in my tomcat's server.xml. The configuration is as below ,
<GlobalNamingResources>
<Resource name="jdbc/abcd"
auth="Container"
type="javax.sql.DataSource"
maxActive="70"
maxWait="10000"
username="xxxx" password="yyyy"
validationQuery="SELECT 1 from dual"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:#xx.xxx.xx.xx:xxxx:zzzz"
testOnBorrow="false"
testOnReturn="false"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="120000"
minEvictableIdleTimeMillis="3600000"
/>
</GlobalNamingResources>
The Resource name configured above , "jdbc/abcd" is the same which the JAR is looking for,
But its not able to find this configured data source . Does anyone know what could be the reason ?
Am getting the below exception ,
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
You need to define a ResourceLink in the web application context that makes the global resource visible to the web application.
<ResourceLink
name="nameThatIsVisibleToTheWebApplication"
global="theGlobalName"
...
You need to do more than just configure Spring.
I'd recommend reading Tomcat JNDI documentation and this.