|
|
|
@ -1,6 +1,7 @@ |
|
|
|
|
package db.config; |
|
|
|
|
|
|
|
|
|
import com.alibaba.druid.pool.DruidDataSource; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.apache.logging.log4j.LogManager; |
|
|
|
|
import org.apache.logging.log4j.Logger; |
|
|
|
|
import org.hibernate.SessionFactory; |
|
|
|
@ -8,10 +9,14 @@ import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
|
import org.springframework.orm.hibernate5.HibernateTransactionManager; |
|
|
|
|
import org.springframework.orm.hibernate5.LocalSessionFactoryBean; |
|
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
|
import org.springframework.util.ReflectionUtils; |
|
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
|
import javax.sql.DataSource; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.lang.reflect.InvocationTargetException; |
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
|
import java.util.Properties; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -43,7 +48,7 @@ public class HibernateConfig{ |
|
|
|
|
@Value("${sessionFactory.scan}") |
|
|
|
|
private String packagesToScan[]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String tableNote="tableNote"; |
|
|
|
|
|
|
|
|
|
private LocalSessionFactoryBean aliyun = new LocalSessionFactoryBean(); |
|
|
|
|
|
|
|
|
@ -76,6 +81,7 @@ public class HibernateConfig{ |
|
|
|
|
bean.setPackagesToScan(packagesToScan); |
|
|
|
|
try { |
|
|
|
|
bean.afterPropertiesSet(); |
|
|
|
|
checkClass(bean); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
@ -106,7 +112,21 @@ public class HibernateConfig{ |
|
|
|
|
return hibernateTransactionManager; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void checkClass(LocalSessionFactoryBean bean){ |
|
|
|
|
for(Class c:bean.getMetadataSources().getAnnotatedClasses()){ |
|
|
|
|
try { |
|
|
|
|
Method method=ReflectionUtils.findMethod(c,tableNote); |
|
|
|
|
Object result=ReflectionUtils.invokeMethod(method,c.newInstance()); |
|
|
|
|
if(ObjectUtils.isEmpty(result)){ |
|
|
|
|
throw new RuntimeException(method+"没有正确重写"); |
|
|
|
|
} |
|
|
|
|
} catch (IllegalAccessException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} catch (InstantiationException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|