parent
d205830b18
commit
2213ddb298
@ -0,0 +1,55 @@ |
||||
package org.pqh.core.util; |
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition; |
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry; |
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.context.ConfigurableApplicationContext; |
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; |
||||
|
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* Created by reborn on 2017/9/19. |
||||
*/ |
||||
public class SpringUtil extends WebMvcConfigurationSupport { |
||||
private static ApplicationContext applicationContext; |
||||
|
||||
public static <T>T getBean(Class<T> c){ |
||||
return applicationContext.getBean(c); |
||||
} |
||||
|
||||
@Override |
||||
public void setApplicationContext(ApplicationContext applicationContext) { |
||||
super.setApplicationContext(applicationContext); |
||||
SpringUtil.applicationContext=applicationContext; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param clazz 注册class |
||||
* @param serviceName 注册别名 |
||||
* @param propertyMap 注入属性 |
||||
*/ |
||||
private static void addBean(Class clazz,String serviceName,Map<String,Object> propertyMap){ |
||||
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(clazz); |
||||
if(propertyMap!=null){ |
||||
for(String key:propertyMap.keySet()){ |
||||
beanDefinitionBuilder.addPropertyValue(key, propertyMap.get(key)); |
||||
} |
||||
} |
||||
registerBean(serviceName, beanDefinitionBuilder.getRawBeanDefinition()); |
||||
} |
||||
|
||||
/** |
||||
* @desc 向spring容器注册bean |
||||
* @param beanName |
||||
* @param beanDefinition |
||||
*/ |
||||
private static void registerBean(String beanName, BeanDefinition beanDefinition) { |
||||
ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) applicationContext; |
||||
BeanDefinitionRegistry beanDefinitonRegistry = (BeanDefinitionRegistry) configurableApplicationContext |
||||
.getBeanFactory(); |
||||
beanDefinitonRegistry.registerBeanDefinition(beanName, beanDefinition); |
||||
} |
||||
} |
@ -1,6 +0,0 @@ |
||||
#dbcp2.url=jdbc:mysql://localhost:3306/bilibili?serverTimezone=UTC&&useSSL=true |
||||
#dbcp2.username=root |
||||
#dbcp2.password=123456 |
||||
dbcp2.url=jdbc:mysql://localhost:3306/bilibili?serverTimezone=UTC&&useSSL=true |
||||
dbcp2.username=root |
||||
dbcp2.password=123456 |
@ -0,0 +1,6 @@ |
||||
hibernate.connection.pool_size=5 |
||||
hibernate.jdbc.fetch_size=50 |
||||
hibernate.dialect=org.hibernate.dialect.MySQL57Dialect |
||||
hibernate.connection.username=root |
||||
hibernate.connection.password=123456 |
||||
hibernate.connection.url=jdbc:mysql://localhost:3306/bilibili?serverTimezone=UTC&&useSSL=true |
Loading…
Reference in new issue