I need to enable local persistence of activemq embedded broker by enabling kahadb. How can i configure kahadb in bean xml file.
<bean id="producerBroker" class="org.apache.activemq.broker.BrokerService" init-method="start" destroy-method="stop">
<property name="brokerName" value = "producerBroker"/>
<property name="persistent" value="true"/>
<property name="transportConnectorURIs">
<list>
<value>tcp://localhost:7005</value>
</list>
</property>
<property name="jmsBridgeConnectors">
<list>
<bean class="org.apache.activemq.network.jms.JmsQueueConnector">
<property name="outboundQueueConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="http://localhost:8090" />
</bean>
</property>
<property name="outboundQueueBridges">
<list>
<bean class="org.apache.activemq.network.jms.OutboundQueueBridge">
<constructor-arg value="qvsample"/>
</bean>
</list>
</property>
</bean>
</list>
</property>
</bean>
EDIT
ActiveMQ's default persistence db is kahoDb. this line <property name="persistent" value="true"/>made this. I need to know how to change this db to another. Moreover i need a good reference to configure spring xml file for activemq?
You can create a bean of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter and inject it into your broker through persistenceAdapter property.
E.g.
<bean id="persistenceAdapter" class="org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter">
<property name="directory" value="D:\test"/>
</bean>
<bean id="producerBroker" class="org.apache.activemq.broker.BrokerService" init-method="start" destroy-method="stop">
<property name="persistenceAdapter" ref="persistenceAdapter"/>
</bean>
You can use any other persistence adapter (e.g. leveldb) as long as it implements org.apache.activemq.store.PersistenceAdapter
Related
I am using Spring Batch 2 version. I am reading data from database using JdbcCursorItemReader.I have successfully fetched the data and also written it to a file.
Below is itemReader bean defined in Job.xml File::
<bean id="itemReader"
class="org.springframework.batch.item.database.JdbcCursorItemReader"
scope="step">
<property name="dataSource" ref="dataSource" />
<property name="sql"
value="select u.ID, u.USER_LOGIN, u.PASSWORD, u.AGE from USERS u" />
</property>
<property name="rowMapper">
<bean class="com.example.UserRowMapper" />
</property>
</bean>
But the issue is,my query is quite big so I just want to keep that query out of xml file and get that query from other file or property file(.property,yaml or xml).
So that I can write xml code as below::
<bean id="itemReader" class="org.springframework.batch.item.database.JdbcCursorItemReader" scope="step">
<property name="dataSource" ref="dataSource" />
<property name="sql" value="$sql_query" />
</property><property name="rowMapper">
<bean class="com.example.UserRowMapper" />
</property>
</bean>
What is best way to achieve this?
<bean id="myProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>path1.properties</value>
<value>path2.properties</value>
.....
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="false"/>
</bean>
...
<bean id="itemReader" class="org.springframework.batch.item.database.JdbcCursorItemReader" scope="step">
<property name="dataSource" ref="dataSource" />
<property name="sql" value="${sql_query}" />
</property><property name="rowMapper">
<bean class="com.example.UserRowMapper" />
</property>
</bean>
path1.properties:
sql_query=value
PropertySourcesPlaceholderConfigurer is preffered in 3.1 and higher, instead of PropertyPlaceholderConfigurer
You can add sql in jobexecutioncontext by using job listener before step.
I am creating a new Spring application to hold a SOAP Web Service, and decided to use Jetty instead of deploying to Tomcat.
So far, the application doesn't have any Starter class and Spring is managing the creation of the Beans.
I am planning to have Jetty start up the Spring context, however I have also heard of Spring Boot which could possibly start Jetty, so which is best ?
I have the below configuration, which is used elsewhere to start Jetty such as this in a Starter class:
ApplicationContext appContext = new ClassPathXmlApplicationContext("service-context.xml");
Server jetty = (Server) appContext.getBean("jettyServer");
However, I'm thinking this can be improved, and that I don't need a Starter class since Spring is creating everything. So, what is the best approach ? Thanks.
<bean id="jettyServer" class="org.eclipse.jetty.server.Server" destroy-method="stop">
<constructor-arg type="org.eclipse.jetty.util.thread.ThreadPool">
<bean id="ThreadPool" class="org.eclipse.jetty.util.thread.QueuedThreadPool">
<property name="minThreads" value="${jetty.min.threads}" />
<property name="maxThreads" value="${jetty.max.threads}" />
</bean>
</constructor-arg>
<property name="connectors">
<list>
<bean id="Connector" class="org.eclipse.jetty.server.ServerConnector">
<constructor-arg ref="jettyServer"/>
<property name="port" value="${jetty.port}" />
</bean>
</list>
</property>
<property name="handler">
<bean class="org.eclipse.jetty.server.handler.HandlerCollection">
<property name="handlers">
<list>
<bean class="org.eclipse.jetty.servlet.ServletContextHandler">
<property name="contextPath" value="/" />
<property name="sessionHandler">
<bean class="org.eclipse.jetty.server.session.SessionHandler" />
</property>
<property name="resourceBase" value="." />
<property name="servletHandler">
<bean class="org.eclipse.jetty.servlet.ServletHandler">
<property name="servlets"> <!-- servlet definition -->
<list>
<!-- default servlet -->
<bean class="org.eclipse.jetty.servlet.ServletHolder">
<property name="name" value="DefaultServlet" />
<property name="servlet">
<!--<bean class="org.eclipse.jetty.servlet.DefaultServlet"/> -->
<bean class="org.springframework.web.servlet.DispatcherServlet" />
</property>
<property name="initParameters">
<map>
<entry key="contextConfigLocation" value="classpath*:**/spring-servlet.xml" />
</map>
</property>
</bean>
</list>
</property>
<property name="servletMappings">
<list><!-- servlet mapping -->
<bean class="org.eclipse.jetty.servlet.ServletMapping">
<property name="pathSpecs">
<list>
<value>/</value>
</list>
</property>
<property name="servletName" value="DefaultServlet" />
</bean>
</list>
</property>
</bean>
</property>
</bean>
</list>
</property>
</bean>
</property>
</bean>
How would I setup container-managed datasources and embedded Active MQ resources to JTATransactionManager for global Transactions?
I am using Tomcat 6 and installed Atomikos in it to support JTA. I use Hibernate for ORM. Here is my configuration:
<bean id="AtomikosTransactionManager"
class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close">
<!-- when close is called, should we force
transactions to terminate or not? -->
<property name="forceShutdown" value="false" />
</bean>
<bean id="AtomikosUserTransaction"
class="com.atomikos.icatch.jta.UserTransactionImp">
<property name="transactionTimeout" value="300" />
</bean>
<jee:jndi-lookup expected-type="javax.sql.DataSource" id="dataSource" jndi-name="jdbc/EDITSOLUTIONS"/>
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources"/>
<list>
<value>../../src/editsolutions.hibernate.cfg.xml</value>
</list>
<property name="hibernateProperties">
<value>
hibernate.dialect=${hibernate.dialect}
</value>
</property>
</bean>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="failover://tcp://localhost:61616"/>
</bean>
</property>
</bean>
<bean id="jmsConnectionFactory"class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="failover://tcp://localhost:61616"/>
</bean>
<bean name="txManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="AtomikosTransactionManager" />
<property name="userTransaction" ref="AtomikosUserTransaction" />
</bean>
Spring documentation says that JTA Transaction Manager need not be told about resources. That's what I have done.
I have the following outstanding questions:
I am not sure whether Atomikos is integrated properly or not?
Is it OK to get the datasource from <jee:jndi-lookup>?
Is Hiberante configuration correct with respect to JTATransactionManager?
As it is embedded in JVM not managed by container, would JTATransactionManager be able to recognize ActimeMQ ?
Try with this very useful link: http://www.atomikos.com/Documentation/SpringIntegration
Remember to configure the datasource in this way:
<bean id="dataSourceA" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
<qualifier value="jmsRecoveryDatabaseSchema"/>
<property name="uniqueResourceName"><value>XADS1</value></property>
<property name="xaDataSourceClassName">
<value>oracle.jdbc.xa.client.OracleXADataSource</value>
</property>
<property name="xaProperties">
<props>
<prop key="URL">${jdbc.url}</prop>
<prop key="user">${jdbc.username}</prop>
<prop key="password">${jdbc.password}</prop>
</props>
</property>
<property name="poolSize"><value>1</value></property>
<property name="testQuery" value="SELECT 1 FROM DUAL"/>
</bean>
I hope it helps!
Is there a way to configure and setup Embedded Tomcat in Spring? I can do so easily with Jetty 7 that I created a standalone Java application that will start Jetty as webcontainer and finally JUnit test can call the BO via HTTPInvoker.
To me, it seems I have to write code to do so by using Tomcat?
Spring xml file
<!-- Manually start server after setting parent context. (init-method="start") -->
<bean id="jettyServer"
class="org.eclipse.jetty.server.Server"
init-method="start"
destroy-method="stop">
<property name="threadPool">
<bean id="ThreadPool"
class="org.eclipse.jetty.util.thread.ExecutorThreadPool">
<constructor-arg value="0" />
<!--property name="corePoolSize" value="${jetty.server.thread.pool.core.pool.size}"/>
<property name="maximumPoolSize" value="${jetty.server.thread.pool.max.pool.size}"/-->
</bean>
</property>
<property name="connectors">
<list>
<bean id="Connector"
class="org.eclipse.jetty.server.nio.SelectChannelConnector"
p:port="${jetty.server.port}"
p:maxIdleTime="${jetty.server.max.idle.time}"
p:acceptors="${jetty.server.acceptor.num}"
p:confidentialPort="${jetty.server.ssl.port}" />
</list>
</property>
<property name="handler">
<bean class="org.eclipse.jetty.server.handler.HandlerCollection">
<property name="handlers">
<list>
<bean class="org.eclipse.jetty.servlet.ServletContextHandler">
<property name="contextPath" value="/"/>
<property name="sessionHandler">
<bean class="org.eclipse.jetty.server.session.SessionHandler"/>
</property>
<property name="resourceBase" value="."/>
<property name="servletHandler">
<bean class="org.eclipse.jetty.servlet.ServletHandler">
<property name="servlets"> <!-- servlet definition -->
<list>
<!-- default servlet -->
<bean class="org.eclipse.jetty.servlet.ServletHolder">
<property name="name" value="DefaultServlet"/>
<property name="servlet">
<bean class="org.springframework.web.servlet.DispatcherServlet"/>
</property>
<property name="initParameters">
<map>
<entry key="contextConfigLocation" value="classpath:config/DefaultServlet-servlet.xml" />
</map>
</property>
</bean>
</list>
</property>
<property name="servletMappings">
<list><!-- servlet mapping -->
<bean class="org.eclipse.jetty.servlet.ServletMapping">
<property name="pathSpecs">
<list><value>/</value></list>
</property>
<property name="servletName" value="DefaultServlet"/>
</bean>
</list>
</property>
</bean>
</property>
</bean>
<bean class="org.eclipse.jetty.server.handler.RequestLogHandler">
<property name="requestLog">
<bean class="org.eclipse.jetty.server.NCSARequestLog">
<constructor-arg value="${jetty.server.log.dir}/jetty-yyyy_mm_dd.log"/>
<property name="extended" value="false"/>
</bean>
</property>
</bean>
</list>
</property>
</bean>
</property>
</bean>
DefaultServlet-servlet.xml
<!-- This default handler takes care of each of the services enumerated below -->
<bean id="defaultHandlerMapping"
class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
<bean id="helloService" class="com.company.ws.bo.HelloServiceImpl"/>
<!-- SpringHTTP Service Exposure -->
<bean name="/HelloService"
class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter"
lazy-init="true">
<property name="service" ref="helloService" />
<property name="serviceInterface"
value="com.company.ws.bo.IHelloService" />
</bean>
Tomcat 7 can be used as an embedded Server. As far as I know there is no special spring support, but you don't need special spring support to start an tomcat out of an spring application.
#See:
this blog and this (german)
I developed a login mechanism for one of my projects with Spring 2.5 , asegi security 1.0.7 and I used Tomcat 6 as my development server.When I was developing the project everything worked fine and I could successfully log-in.The problem begun when I deployed my application on the production server.From the moment I deployed the application on the production tomcat 6 I could not log-in even with the correct username and password and the most weird of all is that no exception is thrown.I just can't log -in!
here is the application-context.xml of the application:
<bean id="authedicationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider">
<property name="userDetailsService" ref="userDetailService"/>
</bean>
<bean id="authenticationEntryPoint" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">
<property name="loginFormUrl" value="/login.htm" />
</bean>
<bean id="filterChainProxy"
class="org.acegisecurity.util.FilterChainProxy">
<property name="filterInvocationDefinitionSource">
<value>
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/**=authenticationProcessingFilter,exceptionTranslationFilter
</value>
</property>
</bean>
<bean id="authenticationProcessingFilter"
class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
<property name="authenticationManager" ref="authenticationManager"/>
<property name="authenticationFailureUrl" value="/error.htm" />
<property name="defaultTargetUrl" value="/admin_menu.htm" />
<property name="filterProcessesUrl" value="/j_acegi_security_check" />
</bean>
<bean id="roleVoter" class="org.acegisecurity.vote.RoleVoter"/>
<bean id="accessDecisionManager" class="org.acegisecurity.vote.UnanimousBased">
<property name="decisionVoters">
<list>
<ref bean="roleVoter"/>
</list>
</property>
<property name="allowIfAllAbstainDecisions" value="true"/>
</bean>
<bean id="filterSecurityInterceptor" class="org.acegisecurity.intercept.web.FilterSecurityInterceptor">
<property name="authenticationManager" ref="authenticationManager"/>
<property name="accessDecisionManager" ref="accessDecisionManager"/>
<property name="objectDefinitionSource">
<value>
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/add_article.htm=ROLE_ADMIN
/add_publication.htm=ROLE_ADMIN
/admin_menu.htm=ROLE_ADMIN
</value>
</bean>
</property>
</bean>
<bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager">
<property name="providers">
<list>
<ref bean="authedicationProvider"/>
</list>
</property>
</bean>
<bean id="userDetailService" class="org.acegisecurity.userdetails.jdbc.JdbcDaoImpl">
<property name="dataSource" ref="datasource"/>
<property name="usersByUsernameQuery">
<value>
SELECT username,password,'true' AS enabled FROM Users where username=?
</value>
</property>
<property name="authoritiesByUsernameQuery">
<value>
SELECT username,role_name FROM Roles r,Users u WHERE r.user=u.id AND u.username=?
</value>
</property>
</bean>
Am I missing somthing?Any help would be really appreciated!Thank you in advance
Is this what you have <bean id="authe**d**icationProvider" in your first line of application file ?