Issue
I am new to JSF and Spring Security. I am building a JSF 2 project based on this tutorial. I want to put the dataSource bean in a java class because I am generating the url for the JDBC connection and users in another class. How to put this code from my security-config.xml to a java class.
<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/spring_security_db" />
<beans:property name="username" value="root" />
<beans:property name="password" value="" />
</beans:bean>
Solution
You should create a new Class which implements DriverManagerDataSource whith is's constructor and then in your beans definiton in the class tag put the name of that Class. Your Class something like this:
package dao;
public class dataSource extends DriverManagerDataSource {
public dataSource() {
// TODO Auto-generated constructor stub
this.setDriverClassName("com.mysql.jdbc.Driver");
this.setUrl("jdbc:mysql://.../.....");
this.setUsername(""); this.setPassword("");
}
}
Your bean definition like that:
<beans:bean id="dataSource" class="dao.dataSource">
Answered By - hamza-don