I been working on a Spring project that been running great in tomcat, we are moving into JBoss and would like to use the datasource setup in JBoss. The project used to work with the following xml..
<beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
> <beans:property name="driverClassName" value="${database.driver}" /> <beans:property
name="url" value="${database.url}" /> <beans:property name="username" value="${database.user}"
/> <beans:property name="password" value="${database.password}" /> <beans:property
name="initialSize" value="5" /> <beans:property name="maxActive" value="10"
/> </beans:bean>
but now that we are moving to JBoss and the Admin would like us to use the datasource setup in JBoss I am trying to use the following.
<jee:jndi-lookup id="dataSourcejndi" jndi-name="dataSourcejndi"
lookup-on-startup="false" proxy-interface="javax.sql.DataSource"
cache="true" resource-ref="true" />
<beans:bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"
lazy-init="true">
<beans:property name="dataSource" ref="dataSourcejndi" />
</beans:bean>
We are getting no errors but the project will not startup anymore..
You should only need the second one. Mine is setup like this:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:My_Data_Source" />
</bean>
Related
I am migrating a Spring XML based app from Jboss to Tomcat to deploy in pcf. But while configuring JTA for Tomcat I'm getting this error -
java.lang.IllegalArgumentException: id to load is required for loading
And I have added all the libraries:
transactions-jta
transactions-api
transactions
transactions-jdbc
atomikos-util
transactions-hibernate4
All the packages are from com.atomikos version is 4.0.6
<bean id="ecfdDataSource_test" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${spring.datasource.driver-class-name}" />
<property name="url" value="${spring.datasource.url}" />
<property name="username" value="${spring.datasource.username}" />
<property name="password" value="${spring.datasource.password}" />
</bean>
<bean id="AtomikosTransactionManager"
class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close">
<property name="forceShutdown" value="false" />
</bean>
<bean id="AtomikosUserTransaction"
class="com.atomikos.icatch.jta.UserTransactionImp">
<property name="transactionTimeout" value="300" />
</bean>
<bean id="transactionManager_test"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="AtomikosTransactionManager" />
<property name="userTransaction" ref="AtomikosUserTransaction" />
</bean>
I am having my properties file in the src/main/resource folder.
messages.properties
messages_en.properties
messages_en_US.properties
Below is the entry in my spring-servlet.xml file.
<resources mapping="/resources/**" location="/resources/" />
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<!-- Localization Settings -->
<beans:bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<beans:property name="basename" value="classpath:messages" />
<beans:property name="defaultEncoding" value="UTF-8" />
</beans:bean>
<beans:bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<beans:property name="defaultLocale" value="en" />
<beans:property name="cookieName" value="appLocaleCookie"></beans:property>
<beans:property name="cookieMaxAge" value="3600"></beans:property>
</beans:bean>
<interceptors>
<beans:bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<beans:property name="paramName" value="locale" />
</beans:bean>
</interceptors>
<!-- Property place holder configuration -->
<beans:bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<beans:property name="location" value="classpath:config.properties" />
</beans:bean>
But I keep getting the following error
javax.servlet.jsp.JspTagException: No message found under code 'application.title' for locale 'en_US'.
at org.springframework.web.servlet.tags.MessageTag.doEndTag(MessageTag.java:200)
at org.apache.jsp.login_jsp._jspx_meth_spring_005fmessage_005f0(login_jsp.java:224)
I had literally tried everything for the basename value with classpath, without classpath but nothing works.
DB Configuration :
servlet-context.xml
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
spring-security.xml
<beans:bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
<beans:property name="url" value="jdbc:mysql://localhost:3306/rni" />
<beans:property name="username" value="root" />
<beans:property name="password" value="root" />
</beans:bean>
In servlet-context.xml i configured database properties from properties file
Same properties i need to use in spring-security.xml
please tell me the way how to approach?
Since both are managed by spring's single container, you can use the EL in spring-security.xml as well
<beans:bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
<beans:property name="url" value="jdbc:mysql://localhost:3306/rni" />
<beans:property name="username" value="${jdbc.username}" />
<beans:property name="password" value="${jdbc.password}" />
</beans:bean>
However I'm not sure why you need two datasources.
I have my java spring standalone project which works fine in windows but when I create jar file and executes that jar file by using shell script, it gives me org.springframework.beans.factory.NoSuchBeanDefinitionException. It seems that in unix it is unable to load the beans and unable to do component scan.
I have application contex file as below:
<context:annotation-config />
<context:component-scan base-package="com.ubs.lazar" />
<context:property-placeholder location="oracle.properties" />
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${batch.jdbc.driver}" />
<property name="url" value="${batch.jdbc.url}" />
<property name="username" value="${batch.jdbc.user}" />
<property name="password" value="${batch.jdbc.password}" />
</bean>
<bean id="daoFactory" class="com.ubs.mzq.xen.db.XenDaoFactory">
<property name="databaseName" value="oracle" />
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven/>
And I am invoking and load the configuration from java as below:
ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:META-INF/application-context.xml");
AwardEventService awardEventService = (AwardEventService) context.getBean("awardEventServiceImpl");
Can you please somebody helps to how to overcome this issue in UNIX.
Thanks
I want to initialize database when application is starting.
In root-context.xml I add this jdbc:initialize-database
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="/WEB-INF/import.sql" />
</jdbc:initialize-database>
My dataSource
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
and jdbc.properties
jdbc.driverClassName=org.postgresql.Driver
jdbc.username=postgres
jdbc.password=z123456z
jdbc.url=jdbc:postgresql://127.0.0.1:5432/answer?charSet=UTF8
I use PostgreSQL 9.2.
In database I have "Структура даних" instead of "Алгоритм".
How to correctly specify this option and solve problem ?
You should use follow:
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="/WEB-INF/import.sql" encoding="UTF-8" />
</jdbc:initialize-database>