mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-05-15 04:52:09 +08:00
v 1.5.0 RC2
v 1.5.0 RC2
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
package org.maxkey.autoconfigure;
|
||||
|
||||
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
|
||||
import java.io.IOException;
|
||||
import javax.sql.DataSource;
|
||||
import org.maxkey.authn.RealmAuthenticationProvider;
|
||||
import org.maxkey.authn.SavedRequestAwareAuthenticationSuccessHandler;
|
||||
import org.maxkey.crypto.password.PasswordReciprocal;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
|
||||
@Configuration
|
||||
@PropertySource("classpath:/application.properties")
|
||||
public class ApplicationAutoConfiguration implements InitializingBean {
|
||||
private static final Logger _logger =
|
||||
LoggerFactory.getLogger(ApplicationAutoConfiguration.class);
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
@ConfigurationProperties("spring.datasource")
|
||||
public DataSource dataSource() {
|
||||
return DruidDataSourceBuilder.create().build();
|
||||
}
|
||||
|
||||
/**
|
||||
* propertySourcesPlaceholderConfigurer .
|
||||
* @return propertySourcesPlaceholderConfigurer
|
||||
* @throws IOException null
|
||||
*/
|
||||
@Bean (name = "propertySourcesPlaceholderConfigurer")
|
||||
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer()
|
||||
throws IOException {
|
||||
ClassPathResource classPathResource1 =
|
||||
new ClassPathResource("/config/applicationConfig.properties");
|
||||
ClassPathResource classPathResource2 = new ClassPathResource("/application.properties");
|
||||
|
||||
PropertySourcesPlaceholderConfigurer configurer =
|
||||
new PropertySourcesPlaceholderConfigurer();
|
||||
configurer.setLocations(
|
||||
classPathResource1,
|
||||
classPathResource2
|
||||
);
|
||||
configurer.setIgnoreUnresolvablePlaceholders(true);
|
||||
_logger.debug("PropertySourcesPlaceholderConfigurer init");
|
||||
return configurer;
|
||||
}
|
||||
|
||||
@Bean(name = "passwordReciprocal")
|
||||
public PasswordReciprocal passwordReciprocal() {
|
||||
return new PasswordReciprocal();
|
||||
}
|
||||
|
||||
@Bean(name = "savedRequestSuccessHandler")
|
||||
public SavedRequestAwareAuthenticationSuccessHandler
|
||||
savedRequestAwareAuthenticationSuccessHandler() {
|
||||
return new SavedRequestAwareAuthenticationSuccessHandler();
|
||||
}
|
||||
|
||||
@Bean(name = "authenticationProvider")
|
||||
public RealmAuthenticationProvider authenticationProvider() {
|
||||
return new RealmAuthenticationProvider();
|
||||
}
|
||||
|
||||
@Bean(name = "jdbcTemplate")
|
||||
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
|
||||
return new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Bean(name = "transactionManager")
|
||||
DataSourceTransactionManager transactionManager(DataSource dataSource) {
|
||||
return new DataSourceTransactionManager(dataSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.maxkey.config;
|
||||
package org.maxkey.autoconfigure;
|
||||
|
||||
import com.google.code.kaptcha.Producer;
|
||||
import com.google.code.kaptcha.impl.DefaultKaptcha;
|
||||
@@ -7,6 +7,7 @@ import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
@@ -14,7 +15,7 @@ import org.springframework.core.io.Resource;
|
||||
|
||||
|
||||
@Configuration
|
||||
public class KaptchaAutoConfiguration {
|
||||
public class KaptchaAutoConfiguration implements InitializingBean {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(KaptchaAutoConfiguration.class);
|
||||
|
||||
/**
|
||||
@@ -33,4 +34,10 @@ public class KaptchaAutoConfiguration {
|
||||
kaptcha.setConfig(config);
|
||||
return kaptcha;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.maxkey.config;
|
||||
package org.maxkey.autoconfigure;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -32,29 +32,6 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
|
||||
public class MvcAutoConfiguration implements InitializingBean {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(MvcAutoConfiguration.class);
|
||||
|
||||
/**
|
||||
* propertySourcesPlaceholderConfigurer .
|
||||
* @return propertySourcesPlaceholderConfigurer
|
||||
* @throws IOException null
|
||||
*/
|
||||
@Bean (name = "propertySourcesPlaceholderConfigurer")
|
||||
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer()
|
||||
throws IOException {
|
||||
ClassPathResource classPathResource1 =
|
||||
new ClassPathResource("/config/applicationConfig.properties");
|
||||
ClassPathResource classPathResource2 = new ClassPathResource("/application.properties");
|
||||
|
||||
PropertySourcesPlaceholderConfigurer configurer =
|
||||
new PropertySourcesPlaceholderConfigurer();
|
||||
configurer.setLocations(
|
||||
classPathResource1,
|
||||
classPathResource2
|
||||
);
|
||||
configurer.setIgnoreUnresolvablePlaceholders(true);
|
||||
|
||||
return configurer;
|
||||
}
|
||||
|
||||
/**
|
||||
* cookieLocaleResolver .
|
||||
* @return cookieLocaleResolver
|
||||
@@ -0,0 +1,71 @@
|
||||
package org.maxkey.autoconfigure;
|
||||
|
||||
import org.maxkey.persistence.redis.RedisConnectionFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
@Configuration
|
||||
@PropertySource("classpath:/application.properties")
|
||||
public class RedisAutoConfiguration implements InitializingBean {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(RedisAutoConfiguration.class);
|
||||
|
||||
/**
|
||||
* RedisConnectionFactory.
|
||||
* @param host String
|
||||
* @param port int
|
||||
* @param timeout int
|
||||
* @param password String
|
||||
* @param maxActive int
|
||||
* @param maxWait int
|
||||
* @param maxIdle int
|
||||
* @param minIdle int
|
||||
* @return RedisConnectionFactory
|
||||
*/
|
||||
@Bean
|
||||
public RedisConnectionFactory redisConnectionFactory(
|
||||
@Value("${spring.redis.host}")
|
||||
String host,
|
||||
@Value("${spring.redis.port}")
|
||||
int port,
|
||||
@Value("${spring.redis.timeout}")
|
||||
int timeout,
|
||||
@Value("${spring.redis.password}")
|
||||
String password,
|
||||
@Value("${spring.redis.lettuce.pool.max-active}")
|
||||
int maxActive,
|
||||
@Value("${spring.redis.jedis.pool.max-wait}")
|
||||
int maxWait,
|
||||
@Value("${spring.redis.jedis.pool.max-idle}")
|
||||
int maxIdle,
|
||||
@Value("${spring.redis.lettuce.pool.min-idle}")
|
||||
int minIdle) {
|
||||
_logger.debug("RedisConnectionFactory init .");
|
||||
RedisConnectionFactory factory = new RedisConnectionFactory();
|
||||
factory.setHostName(host);
|
||||
factory.setPort(port);
|
||||
factory.setTimeOut(timeout);
|
||||
factory.setPassword(password);
|
||||
|
||||
JedisPoolConfig poolConfig = new JedisPoolConfig();
|
||||
poolConfig.setMaxIdle(maxIdle);
|
||||
poolConfig.setMinIdle(minIdle);
|
||||
poolConfig.setMaxTotal(maxActive);
|
||||
poolConfig.setMaxWaitMillis(maxWait);
|
||||
|
||||
factory.setPoolConfig(poolConfig);
|
||||
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user