Trying to set up a dataSource on Spring for authorisation via MySQL - security beans not loading/autowired...












0















I am getting this error



SEVERE: Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfig': Unsatisfied dependency expressed through field 'securityDataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596)


and this one below



SEVERE: Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener] org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfig': Unsatisfied dependency expressed through field 'securityDataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}


I have supplied below my Java Config and Security config files.



Today I was working on implementing AuthenticationManagerBuilder with JDBC following a tutorial. I amended my DataSource bean to fit the one in tutorial and now I am getting this issue. Authentication worked fine before, so did DB connection and hibernate interactions.



Not sure where to even start looking now.




Here is my Java config file




@Configuration
@EnableWebMvc
@EnableTransactionManagement
@ComponentScan(basePackages= {"domain.applicationform","domain.config","domain.service","domain.dao"})
@PropertySource("classpath:persistence-mysql.properties")
public class ConfigClass extends WebMvcConfigurerAdapter {


//Var to hold props and converter for ints
@Autowired
private Environment env;
private int getIntProperty(String propName) {
String propVal = env.getProperty(propName);
int val = Integer.parseInt(propVal);
return val;
}

// logger
private Logger logger = Logger.getLogger(getClass().getName());

//ViewResolver

@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();

viewResolver.setPrefix("/WEB-INF/view/");
viewResolver.setSuffix(".jsp");

return viewResolver;
}

public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}

@Bean
public DataSource securityDataSource() {
ComboPooledDataSource securityDataSource = new ComboPooledDataSource();

try {
securityDataSource.setDriverClass(env.getProperty("jdbc.driver"));
} catch (PropertyVetoException e) {
throw new RuntimeException(e);
}

//logging
logger.info(">>> jdbc.url=" + env.getProperty("jdbc.url"));
logger.info(">>> jdbc.user=" + env.getProperty("jdbc.user"));

securityDataSource.setJdbcUrl(env.getProperty("jdbc.url"));
securityDataSource.setUser(env.getProperty("jdbc.user"));
securityDataSource.setPassword(env.getProperty("jdbc.password"));

securityDataSource.setInitialPoolSize(getIntProperty("connection.pool.initialPoolSize"));
securityDataSource.setMinPoolSize(getIntProperty("connection.pool.minPoolSize"));
securityDataSource.setMaxPoolSize(getIntProperty("connection.pool.maxPoolSize"));
securityDataSource.setMaxIdleTime(getIntProperty("connection.pool.maxIdleTime"));
return securityDataSource;
}

private final Properties hibernateProperties() {
Properties hibernateProperties = new Properties();
//properties hibernateProperties.setProperty()

return hibernateProperties;
}

@Bean
public LocalSessionFactoryBean sessionFactory() throws ClassNotFoundException {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(securityDataSource());
//sessionFactory.setAnnotatedClasses(new Class { EqualOps.class });
sessionFactory.setPackagesToScan(
new String { "domain.applicationform","domain.dao","domain.service","domain.config"});
sessionFactory.setHibernateProperties(hibernateProperties());

return sessionFactory;
}

@Bean
public PlatformTransactionManager hibernateTransactionManager() throws ClassNotFoundException {
HibernateTransactionManager transactionManager
= new HibernateTransactionManager();
transactionManager.setSessionFactory(sessionFactory().getObject());
return transactionManager;
}

}



Here is my SecurityConfig




package domain.config;


import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;


@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private DataSource securityDataSource;

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(securityDataSource);
}
@Override
protected void configure(HttpSecurity http) throws Exception {

http.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/management/manager/**").hasRole("MANAGER")
.antMatchers("/management/recruitment/**").hasRole("RECRUITER")
.antMatchers("/management/equalops/**").hasRole("RECRUITER")
.antMatchers("/management/systems/**").hasRole("ADMIN")
.and()
.formLogin()
.loginPage("/authenticationPage")
.loginProcessingUrl("/authenticateUser")
.permitAll()
.and()
.logout().permitAll()
.and()
.exceptionHandling().accessDeniedPage("/access-denied");
}
}



EDIT1




My apologoies, forgot to post properties file.



jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/new
jdbc.user=root
jdbc.password=root

connection.pool.initialPoolSize=5
connection.pool.minPoolSize=5
connection.pool.maxPoolSize=20
connection.pool.maxIdleTime=3000









share|improve this question

























  • can you post your application.properties file?

    – stacker
    Nov 24 '18 at 21:03











  • @slimane , post edited.

    – Yanis K
    Nov 24 '18 at 21:14











  • Are your logging messages printed when the application starts?

    – akuma8
    Nov 24 '18 at 21:32











  • @akuma8 if I am, I am unaware of it. (could you elaborate what do you mean)

    – Yanis K
    Nov 24 '18 at 21:35













  • Just to know if the bean is really instantiated or not.

    – akuma8
    Nov 24 '18 at 21:36
















0















I am getting this error



SEVERE: Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfig': Unsatisfied dependency expressed through field 'securityDataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596)


and this one below



SEVERE: Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener] org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfig': Unsatisfied dependency expressed through field 'securityDataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}


I have supplied below my Java Config and Security config files.



Today I was working on implementing AuthenticationManagerBuilder with JDBC following a tutorial. I amended my DataSource bean to fit the one in tutorial and now I am getting this issue. Authentication worked fine before, so did DB connection and hibernate interactions.



Not sure where to even start looking now.




Here is my Java config file




@Configuration
@EnableWebMvc
@EnableTransactionManagement
@ComponentScan(basePackages= {"domain.applicationform","domain.config","domain.service","domain.dao"})
@PropertySource("classpath:persistence-mysql.properties")
public class ConfigClass extends WebMvcConfigurerAdapter {


//Var to hold props and converter for ints
@Autowired
private Environment env;
private int getIntProperty(String propName) {
String propVal = env.getProperty(propName);
int val = Integer.parseInt(propVal);
return val;
}

// logger
private Logger logger = Logger.getLogger(getClass().getName());

//ViewResolver

@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();

viewResolver.setPrefix("/WEB-INF/view/");
viewResolver.setSuffix(".jsp");

return viewResolver;
}

public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}

@Bean
public DataSource securityDataSource() {
ComboPooledDataSource securityDataSource = new ComboPooledDataSource();

try {
securityDataSource.setDriverClass(env.getProperty("jdbc.driver"));
} catch (PropertyVetoException e) {
throw new RuntimeException(e);
}

//logging
logger.info(">>> jdbc.url=" + env.getProperty("jdbc.url"));
logger.info(">>> jdbc.user=" + env.getProperty("jdbc.user"));

securityDataSource.setJdbcUrl(env.getProperty("jdbc.url"));
securityDataSource.setUser(env.getProperty("jdbc.user"));
securityDataSource.setPassword(env.getProperty("jdbc.password"));

securityDataSource.setInitialPoolSize(getIntProperty("connection.pool.initialPoolSize"));
securityDataSource.setMinPoolSize(getIntProperty("connection.pool.minPoolSize"));
securityDataSource.setMaxPoolSize(getIntProperty("connection.pool.maxPoolSize"));
securityDataSource.setMaxIdleTime(getIntProperty("connection.pool.maxIdleTime"));
return securityDataSource;
}

private final Properties hibernateProperties() {
Properties hibernateProperties = new Properties();
//properties hibernateProperties.setProperty()

return hibernateProperties;
}

@Bean
public LocalSessionFactoryBean sessionFactory() throws ClassNotFoundException {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(securityDataSource());
//sessionFactory.setAnnotatedClasses(new Class { EqualOps.class });
sessionFactory.setPackagesToScan(
new String { "domain.applicationform","domain.dao","domain.service","domain.config"});
sessionFactory.setHibernateProperties(hibernateProperties());

return sessionFactory;
}

@Bean
public PlatformTransactionManager hibernateTransactionManager() throws ClassNotFoundException {
HibernateTransactionManager transactionManager
= new HibernateTransactionManager();
transactionManager.setSessionFactory(sessionFactory().getObject());
return transactionManager;
}

}



Here is my SecurityConfig




package domain.config;


import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;


@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private DataSource securityDataSource;

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(securityDataSource);
}
@Override
protected void configure(HttpSecurity http) throws Exception {

http.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/management/manager/**").hasRole("MANAGER")
.antMatchers("/management/recruitment/**").hasRole("RECRUITER")
.antMatchers("/management/equalops/**").hasRole("RECRUITER")
.antMatchers("/management/systems/**").hasRole("ADMIN")
.and()
.formLogin()
.loginPage("/authenticationPage")
.loginProcessingUrl("/authenticateUser")
.permitAll()
.and()
.logout().permitAll()
.and()
.exceptionHandling().accessDeniedPage("/access-denied");
}
}



EDIT1




My apologoies, forgot to post properties file.



jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/new
jdbc.user=root
jdbc.password=root

connection.pool.initialPoolSize=5
connection.pool.minPoolSize=5
connection.pool.maxPoolSize=20
connection.pool.maxIdleTime=3000









share|improve this question

























  • can you post your application.properties file?

    – stacker
    Nov 24 '18 at 21:03











  • @slimane , post edited.

    – Yanis K
    Nov 24 '18 at 21:14











  • Are your logging messages printed when the application starts?

    – akuma8
    Nov 24 '18 at 21:32











  • @akuma8 if I am, I am unaware of it. (could you elaborate what do you mean)

    – Yanis K
    Nov 24 '18 at 21:35













  • Just to know if the bean is really instantiated or not.

    – akuma8
    Nov 24 '18 at 21:36














0












0








0








I am getting this error



SEVERE: Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfig': Unsatisfied dependency expressed through field 'securityDataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596)


and this one below



SEVERE: Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener] org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfig': Unsatisfied dependency expressed through field 'securityDataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}


I have supplied below my Java Config and Security config files.



Today I was working on implementing AuthenticationManagerBuilder with JDBC following a tutorial. I amended my DataSource bean to fit the one in tutorial and now I am getting this issue. Authentication worked fine before, so did DB connection and hibernate interactions.



Not sure where to even start looking now.




Here is my Java config file




@Configuration
@EnableWebMvc
@EnableTransactionManagement
@ComponentScan(basePackages= {"domain.applicationform","domain.config","domain.service","domain.dao"})
@PropertySource("classpath:persistence-mysql.properties")
public class ConfigClass extends WebMvcConfigurerAdapter {


//Var to hold props and converter for ints
@Autowired
private Environment env;
private int getIntProperty(String propName) {
String propVal = env.getProperty(propName);
int val = Integer.parseInt(propVal);
return val;
}

// logger
private Logger logger = Logger.getLogger(getClass().getName());

//ViewResolver

@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();

viewResolver.setPrefix("/WEB-INF/view/");
viewResolver.setSuffix(".jsp");

return viewResolver;
}

public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}

@Bean
public DataSource securityDataSource() {
ComboPooledDataSource securityDataSource = new ComboPooledDataSource();

try {
securityDataSource.setDriverClass(env.getProperty("jdbc.driver"));
} catch (PropertyVetoException e) {
throw new RuntimeException(e);
}

//logging
logger.info(">>> jdbc.url=" + env.getProperty("jdbc.url"));
logger.info(">>> jdbc.user=" + env.getProperty("jdbc.user"));

securityDataSource.setJdbcUrl(env.getProperty("jdbc.url"));
securityDataSource.setUser(env.getProperty("jdbc.user"));
securityDataSource.setPassword(env.getProperty("jdbc.password"));

securityDataSource.setInitialPoolSize(getIntProperty("connection.pool.initialPoolSize"));
securityDataSource.setMinPoolSize(getIntProperty("connection.pool.minPoolSize"));
securityDataSource.setMaxPoolSize(getIntProperty("connection.pool.maxPoolSize"));
securityDataSource.setMaxIdleTime(getIntProperty("connection.pool.maxIdleTime"));
return securityDataSource;
}

private final Properties hibernateProperties() {
Properties hibernateProperties = new Properties();
//properties hibernateProperties.setProperty()

return hibernateProperties;
}

@Bean
public LocalSessionFactoryBean sessionFactory() throws ClassNotFoundException {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(securityDataSource());
//sessionFactory.setAnnotatedClasses(new Class { EqualOps.class });
sessionFactory.setPackagesToScan(
new String { "domain.applicationform","domain.dao","domain.service","domain.config"});
sessionFactory.setHibernateProperties(hibernateProperties());

return sessionFactory;
}

@Bean
public PlatformTransactionManager hibernateTransactionManager() throws ClassNotFoundException {
HibernateTransactionManager transactionManager
= new HibernateTransactionManager();
transactionManager.setSessionFactory(sessionFactory().getObject());
return transactionManager;
}

}



Here is my SecurityConfig




package domain.config;


import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;


@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private DataSource securityDataSource;

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(securityDataSource);
}
@Override
protected void configure(HttpSecurity http) throws Exception {

http.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/management/manager/**").hasRole("MANAGER")
.antMatchers("/management/recruitment/**").hasRole("RECRUITER")
.antMatchers("/management/equalops/**").hasRole("RECRUITER")
.antMatchers("/management/systems/**").hasRole("ADMIN")
.and()
.formLogin()
.loginPage("/authenticationPage")
.loginProcessingUrl("/authenticateUser")
.permitAll()
.and()
.logout().permitAll()
.and()
.exceptionHandling().accessDeniedPage("/access-denied");
}
}



EDIT1




My apologoies, forgot to post properties file.



jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/new
jdbc.user=root
jdbc.password=root

connection.pool.initialPoolSize=5
connection.pool.minPoolSize=5
connection.pool.maxPoolSize=20
connection.pool.maxIdleTime=3000









share|improve this question
















I am getting this error



SEVERE: Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfig': Unsatisfied dependency expressed through field 'securityDataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596)


and this one below



SEVERE: Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener] org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfig': Unsatisfied dependency expressed through field 'securityDataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}


I have supplied below my Java Config and Security config files.



Today I was working on implementing AuthenticationManagerBuilder with JDBC following a tutorial. I amended my DataSource bean to fit the one in tutorial and now I am getting this issue. Authentication worked fine before, so did DB connection and hibernate interactions.



Not sure where to even start looking now.




Here is my Java config file




@Configuration
@EnableWebMvc
@EnableTransactionManagement
@ComponentScan(basePackages= {"domain.applicationform","domain.config","domain.service","domain.dao"})
@PropertySource("classpath:persistence-mysql.properties")
public class ConfigClass extends WebMvcConfigurerAdapter {


//Var to hold props and converter for ints
@Autowired
private Environment env;
private int getIntProperty(String propName) {
String propVal = env.getProperty(propName);
int val = Integer.parseInt(propVal);
return val;
}

// logger
private Logger logger = Logger.getLogger(getClass().getName());

//ViewResolver

@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();

viewResolver.setPrefix("/WEB-INF/view/");
viewResolver.setSuffix(".jsp");

return viewResolver;
}

public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}

@Bean
public DataSource securityDataSource() {
ComboPooledDataSource securityDataSource = new ComboPooledDataSource();

try {
securityDataSource.setDriverClass(env.getProperty("jdbc.driver"));
} catch (PropertyVetoException e) {
throw new RuntimeException(e);
}

//logging
logger.info(">>> jdbc.url=" + env.getProperty("jdbc.url"));
logger.info(">>> jdbc.user=" + env.getProperty("jdbc.user"));

securityDataSource.setJdbcUrl(env.getProperty("jdbc.url"));
securityDataSource.setUser(env.getProperty("jdbc.user"));
securityDataSource.setPassword(env.getProperty("jdbc.password"));

securityDataSource.setInitialPoolSize(getIntProperty("connection.pool.initialPoolSize"));
securityDataSource.setMinPoolSize(getIntProperty("connection.pool.minPoolSize"));
securityDataSource.setMaxPoolSize(getIntProperty("connection.pool.maxPoolSize"));
securityDataSource.setMaxIdleTime(getIntProperty("connection.pool.maxIdleTime"));
return securityDataSource;
}

private final Properties hibernateProperties() {
Properties hibernateProperties = new Properties();
//properties hibernateProperties.setProperty()

return hibernateProperties;
}

@Bean
public LocalSessionFactoryBean sessionFactory() throws ClassNotFoundException {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(securityDataSource());
//sessionFactory.setAnnotatedClasses(new Class { EqualOps.class });
sessionFactory.setPackagesToScan(
new String { "domain.applicationform","domain.dao","domain.service","domain.config"});
sessionFactory.setHibernateProperties(hibernateProperties());

return sessionFactory;
}

@Bean
public PlatformTransactionManager hibernateTransactionManager() throws ClassNotFoundException {
HibernateTransactionManager transactionManager
= new HibernateTransactionManager();
transactionManager.setSessionFactory(sessionFactory().getObject());
return transactionManager;
}

}



Here is my SecurityConfig




package domain.config;


import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;


@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private DataSource securityDataSource;

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(securityDataSource);
}
@Override
protected void configure(HttpSecurity http) throws Exception {

http.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/management/manager/**").hasRole("MANAGER")
.antMatchers("/management/recruitment/**").hasRole("RECRUITER")
.antMatchers("/management/equalops/**").hasRole("RECRUITER")
.antMatchers("/management/systems/**").hasRole("ADMIN")
.and()
.formLogin()
.loginPage("/authenticationPage")
.loginProcessingUrl("/authenticateUser")
.permitAll()
.and()
.logout().permitAll()
.and()
.exceptionHandling().accessDeniedPage("/access-denied");
}
}



EDIT1




My apologoies, forgot to post properties file.



jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/new
jdbc.user=root
jdbc.password=root

connection.pool.initialPoolSize=5
connection.pool.minPoolSize=5
connection.pool.maxPoolSize=20
connection.pool.maxIdleTime=3000






java spring spring-mvc spring-security






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 21:13







Yanis K

















asked Nov 24 '18 at 20:34









Yanis KYanis K

6810




6810













  • can you post your application.properties file?

    – stacker
    Nov 24 '18 at 21:03











  • @slimane , post edited.

    – Yanis K
    Nov 24 '18 at 21:14











  • Are your logging messages printed when the application starts?

    – akuma8
    Nov 24 '18 at 21:32











  • @akuma8 if I am, I am unaware of it. (could you elaborate what do you mean)

    – Yanis K
    Nov 24 '18 at 21:35













  • Just to know if the bean is really instantiated or not.

    – akuma8
    Nov 24 '18 at 21:36



















  • can you post your application.properties file?

    – stacker
    Nov 24 '18 at 21:03











  • @slimane , post edited.

    – Yanis K
    Nov 24 '18 at 21:14











  • Are your logging messages printed when the application starts?

    – akuma8
    Nov 24 '18 at 21:32











  • @akuma8 if I am, I am unaware of it. (could you elaborate what do you mean)

    – Yanis K
    Nov 24 '18 at 21:35













  • Just to know if the bean is really instantiated or not.

    – akuma8
    Nov 24 '18 at 21:36

















can you post your application.properties file?

– stacker
Nov 24 '18 at 21:03





can you post your application.properties file?

– stacker
Nov 24 '18 at 21:03













@slimane , post edited.

– Yanis K
Nov 24 '18 at 21:14





@slimane , post edited.

– Yanis K
Nov 24 '18 at 21:14













Are your logging messages printed when the application starts?

– akuma8
Nov 24 '18 at 21:32





Are your logging messages printed when the application starts?

– akuma8
Nov 24 '18 at 21:32













@akuma8 if I am, I am unaware of it. (could you elaborate what do you mean)

– Yanis K
Nov 24 '18 at 21:35







@akuma8 if I am, I am unaware of it. (could you elaborate what do you mean)

– Yanis K
Nov 24 '18 at 21:35















Just to know if the bean is really instantiated or not.

– akuma8
Nov 24 '18 at 21:36





Just to know if the bean is really instantiated or not.

– akuma8
Nov 24 '18 at 21:36












1 Answer
1






active

oldest

votes


















0














Spring boot datasource AutoConfiguration happens in application.properties. you need to specify the right properties in order to be recognized by spring.



try to use this:



spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=


Here you can find common properties supported by spring boot






share|improve this answer
























  • Is that the same case for Spring MVC, because I am using spring-mvc?

    – Yanis K
    Nov 24 '18 at 23:04













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462136%2ftrying-to-set-up-a-datasource-on-spring-for-authorisation-via-mysql-security-b%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Spring boot datasource AutoConfiguration happens in application.properties. you need to specify the right properties in order to be recognized by spring.



try to use this:



spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=


Here you can find common properties supported by spring boot






share|improve this answer
























  • Is that the same case for Spring MVC, because I am using spring-mvc?

    – Yanis K
    Nov 24 '18 at 23:04


















0














Spring boot datasource AutoConfiguration happens in application.properties. you need to specify the right properties in order to be recognized by spring.



try to use this:



spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=


Here you can find common properties supported by spring boot






share|improve this answer
























  • Is that the same case for Spring MVC, because I am using spring-mvc?

    – Yanis K
    Nov 24 '18 at 23:04
















0












0








0







Spring boot datasource AutoConfiguration happens in application.properties. you need to specify the right properties in order to be recognized by spring.



try to use this:



spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=


Here you can find common properties supported by spring boot






share|improve this answer













Spring boot datasource AutoConfiguration happens in application.properties. you need to specify the right properties in order to be recognized by spring.



try to use this:



spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=


Here you can find common properties supported by spring boot







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 22:18









stackerstacker

1,39627




1,39627













  • Is that the same case for Spring MVC, because I am using spring-mvc?

    – Yanis K
    Nov 24 '18 at 23:04





















  • Is that the same case for Spring MVC, because I am using spring-mvc?

    – Yanis K
    Nov 24 '18 at 23:04



















Is that the same case for Spring MVC, because I am using spring-mvc?

– Yanis K
Nov 24 '18 at 23:04







Is that the same case for Spring MVC, because I am using spring-mvc?

– Yanis K
Nov 24 '18 at 23:04




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462136%2ftrying-to-set-up-a-datasource-on-spring-for-authorisation-via-mysql-security-b%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks