JdbcHttpSessionConfiguration messes my Bean Constants - java

I am using spring MVC 4.2 I have this code in my app-context.xml
<bean id="beanConstants" name="beanConstants" class="com.my.web.controller.BeanConstants">
<property name="dbProplocation" value="/my/database.properties" />
<property name="extractDbProplocation" value="/my/extract.database.properties" />
<property name="cssLocation" value="uncompiled" />
<property name="enableSuspensionPollingStr" value="false" />
</bean>
<!-- JDBC Session Config -->
<bean class="org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration"/>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="${hibernate.connection.url}" />
<property name="username" value="${hibernate.connection.username}" />
<property name="password" value="${hibernate.connection.password}" />
</bean>
Now this all worked fine until I added the JdbcHttpSessionConfiguration bean. If I take that line out, it works. otherwise I get this:
Caused by: java.lang.IllegalArgumentException:
Could not resolve placeholder 'hibernate.connection.url' in string value "${hibernate.connection.url}"
I am trying to save the sesstion info in the DB. Why is this doing this? What has one got to do with the other?

Related

How to provide data source entry in spring annotation based project.

I am using spring 3 but my configuration is xml based in which I am trying to convert my project into annotation based using #configuration annotation.
I am little confused how to add data source entry as #Bean for two below cases
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/myds" />
</bean>
<bean id="data_source" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="url1" />
<property name="username" value="user1" />
<property name="password" value="****" />
</bean>

Using JDBC connection with property config Throwing outofmemoryerror

<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://xxx.xx.xxx.xxx:3306/vod6?autoReconnect=true" />
<!-- <property name="url" value="jdbc:mysql://xxx.xx.xxx.xxx:3306/vod2?autoReconnect=true" /> -->
<property name="username" value="voddb" />
<property name="password" value="vod#123" />
</bean>
above config xml working fine .
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${mysql.driverClassName}" />
<property name="url" value="${mysql.url}" />
<property name="username" value="${mysql.username}" />
<property name="password" value="${mysql.password}" />
</bean>
When I am trying to configure jdbc.property and configure them throwing error out of memory
Can you please explain what i am missing?
mysql.database=MYSQL
mysql.driverClassName=com.mysql.jdbc.Driver
mysql.url=jdbc:mysql://xxx.xx.xxx.xxx:3306/vod?autoReconnect=true
mysql.username=voddb
mysql.password=vod#123
mysql.initialSize=4
mysql.maxActive=30
property file
Please confirm whether the placeholder is mentioned correctly in applicationContext.xml file
<context:property-placeholder location="classpath*:catalina.properties" ignore-unresolvable="true"/>
If this is configured correctly please try removing mysql.initialSize=4 mysql.maxActive=30 from properties file and test, this may be thr root cause. Because this is the additional property you have mentioned in properties file
You can try configuring these maxActive,initialSize values in xml itself as property.
<property name="removeAbandonedTimeout" value="180"/>
<property name="removeAbandoned" value="true"/>
<property name="logAbandoned" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="5000"/>
<property name="minEvictableIdleTimeMillis" value="900000"/>
<property name="maxActive" value="20"/>
<property name="maxIdle" value="4"/>

Use property file's property in spring mvc configuration servlet xml

I use following line of code to read config.properties file in my spring mvc configuration servlet xml file.
<context:property-placeholder location="file:///${config.properties}" />
config.properties contains a property say: propertyName = propertyValue
I want to use this propertyName's value in spring mvc configuration servlet xml file.
Here is an example of configuring as pool with properties taken from a properties file
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:#${database.url}" />
<property name="username" value="${database.username}" />
<property name="password" value="${database.password}" />
<property name="validationQuery" value="SELECT 1 FROM DUAL" />
<property name="testWhileIdle" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="300000" />
<property name="numTestsPerEvictionRun" value="6" />
<property name="minEvictableIdleTimeMillis" value="1800000" />
<property name="initialSize" value="3" />
<property name="maxActive" value="75" />
<property name="maxIdle" value="75" />
<property name="maxWait" value="5000" />
<property name="poolPreparedStatements" value="true" />
<property name="maxOpenPreparedStatements" value="100" />
</bean>
The property file contains there rows
database.url=localhost:1521:xe
database.username=dbusername
database.password=dbpassword
I guess you need to add
<context:property-placeholder location="file:///${config.properties}" />
to your servlet.xml file.

FileNotFoundException while running Spring and Ibatis based application on Tomcat

I am using Spring, ibatis for ORM. My app-config.xml look like
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://192.168.10.50/lmexdb_v1" />
<property name="username" value="lmexdba" />
<property name="password" value="lmexdba123#" />
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation"
value="classpath:com/platysgroup/lmex/server/mobile/dao/ibatis/SqlMapConfig.xml" />
</bean>
<bean id="mobileController" class="com.platysgroup.lmex.server.controller.MobileController">
<property name="announcementService" ref="announcementService"></property>
<property name="courseService" ref="courseService"></property>
<property name="userService" ref="userService"></property>
</bean>
and I have my sqlmapconfig.xml file in src/webapp/spring.
But when I run my application on tomcat it show me a exception:
java.io.FileNotFoundException: class path resource [com/platysgroup/lmex/server/mobile/dao/ibatis/SqlMapConfig.xml] cannot be opened because it does not exist
put it in src , and it will be available
if you are using maven project then add it to resource

How to inject the driverClassLoader property in spring?

I have the following partial spring context xml file:
<bean name="template" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource" />
</bean>
<bean name="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassLoader" value="" /> <!-- THIS PROPERTY -->
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3061/my_database" />
<property name="username" value="username" />
<property name="password" value="password" />
<property name="initialSize" value="8" />
</bean>
How do I inject the driverClassLoader property? (I'm using some custom plug-in architecture but not the spring dm server so have to provide a classloader to find the mysql driver)
this apache dbcp classloader bug was just fixed in march 2011.
It may fix your root issue so you don't need to inject the classloader...
https://issues.apache.org/jira/browse/DBCP-333
without this bug fix I don't think the driverClassloader setter was working....
I think you want to use the PropertyPlaceholderConfigurer. Look at section 3.7.2.1 in the Spring 2.0 reference guide.

Categories

Resources