Cześć mam problem którego od dłuższego czasu nie mogę rozwiązać. W programie tworzy się "konflikt" po dodaniu zależności JDBC i JPA. Jeżeli te dwie zależnosci są w projekcie to nie mogę stworzyć bena. Może ktoś coś podpowie. W projekcie są trzy klasy.
Klasa: DemoSecurityConfig
@Configuration
@EnableWebSecurity
@ComponentScan(basePackages="CarSupportApplication")
@PropertySource("classpath:persistence-mysql.properties")
public class DemoSecurityConfig extends WebSecurityConfigurerAdapter
{
@Autowired
private Environment env;
private Logger logger = Logger.getLogger(getClass().getName());
@Autowired
private DataSource securityDataSource;
@Bean
public DataSource securityDataSource() {
// create connection pool
ComboPooledDataSource securityDataSource = new ComboPooledDataSource();
// set the jdbc driver class
try
{
securityDataSource.setDriverClass(env.getProperty("jdbc.driver"));
}
catch (PropertyVetoException exc)
{
throw new RuntimeException(exc);
}
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 int getIntProperty(String propName) {
String propVal = env.getProperty(propName);
int intPropVal = Integer.parseInt(propVal);
return intPropVal;
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(securityDataSource);
}
@Override
protected void configure(HttpSecurity http) throws Exception
{
http.authorizeRequests()
.antMatchers("/hidden-page/**").hasRole("EMPLOYEE")
.antMatchers("/").permitAll()
.and()
.formLogin()
.loginPage("/login-form")
.loginProcessingUrl("/authenticateTheUser")
.defaultSuccessUrl("/hidden-page",true)
.permitAll()
.and()
.logout().permitAll()
.and()
.exceptionHandling()
.accessDeniedPage("/access-denied");
}
}
Klasa: MySpringMvcDispacherServletInitializer
public class MySpringMvcDispacherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
// TODO Auto-generated method stub
return null;
}
@Override
protected Class<?>[] getServletConfigClasses() {
// TODO Auto-generated method stub
return new Class[] {DemoSecurityConfig.class};
}
@Override
protected String[] getServletMappings() {
// TODO Auto-generated method stub
return new String[] {"/"};
}
}
Klasa: SecurityWebApplicationInitializer
public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer
{
}
Stack tracer:
Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'securityDataSource': Requested bean is currently in creation: Is there an unresolvable circular reference?
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.beforeSingletonCreation(DefaultSingletonBeanRegistry.java:339)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'demoSecurityConfig': Unsatisfied dependency expressed through field 'securityDataSource'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'securityDataSource': Requested bean is currently in creation: Is there an unresolvable circular reference?
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]