弹幕下载

master
10295 7 years ago
parent 2e7f33b451
commit a16702d659
  1. 14
      web/src/main/java/web/config/SpringConfig.java
  2. 5
      web/src/main/java/web/html/ElementId.java
  3. 6
      web/src/main/java/web/util/DynamicTimer.java
  4. 4
      web/src/test/java/Test.java

@ -1,20 +1,16 @@
package web.config; package web.config;
import db.config.HibernateConfig; import db.config.HibernateConfig;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource; import org.springframework.context.annotation.PropertySource;
import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.orm.hibernate5.support.OpenSessionInViewInterceptor; import org.springframework.orm.hibernate5.support.OpenSessionInViewInterceptor;
import org.springframework.web.servlet.config.annotation.*; import org.springframework.web.servlet.config.annotation.*;
import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Created by reborn on 2017/7/28. * Created by reborn on 2017/7/28.
@ -25,8 +21,6 @@ import java.util.Map;
@ComponentScan({"web.controller","web.service","web.util"}) @ComponentScan({"web.controller","web.service","web.util"})
public class SpringConfig implements WebMvcConfigurer { public class SpringConfig implements WebMvcConfigurer {
@Resource
private DefaultListableBeanFactory beanFactory;
@Override @Override
public void configureViewResolvers(ViewResolverRegistry registry) { public void configureViewResolvers(ViewResolverRegistry registry) {
@ -42,13 +36,11 @@ public class SpringConfig implements WebMvcConfigurer {
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
Map<String, HibernateTemplate> hibernateTemplateMap= HibernateConfig.get(); HibernateConfig.get().forEach((key,hibernateTemplate)->{
for(String key:hibernateTemplateMap.keySet()) {
OpenSessionInViewInterceptor interceptor = new OpenSessionInViewInterceptor(); OpenSessionInViewInterceptor interceptor = new OpenSessionInViewInterceptor();
interceptor.setSessionFactory(hibernateTemplateMap.get(key).getSessionFactory()); interceptor.setSessionFactory(hibernateTemplate.getSessionFactory());
registry.addWebRequestInterceptor(interceptor); registry.addWebRequestInterceptor(interceptor);
} });
} }
@Override @Override

@ -1,5 +1,6 @@
package web.html; package web.html;
import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -21,9 +22,7 @@ public enum ElementId {
public static Map<String,ElementId> getAll(){ public static Map<String,ElementId> getAll(){
Map<String,ElementId> map=new HashMap<>(); Map<String,ElementId> map=new HashMap<>();
for(ElementId id:ElementId.values()){ EnumSet.allOf(ElementId.class).forEach(elementId -> map.put(elementId.name(),elementId));
map.put(id.name(),id);
}
return map; return map;
} }
} }

@ -18,7 +18,6 @@ import javax.annotation.PostConstruct;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* Created by reborn on 2017/5/8. * Created by reborn on 2017/5/8.
@ -34,10 +33,7 @@ public class DynamicTimer extends ScheduledTaskRegistrar {
@PostConstruct @PostConstruct
public void init(){ public void init(){
List<ScheduledTaskEntity> taskList=hibernateTemplate.loadAll(ScheduledTaskEntity.class); hibernateTemplate.loadAll(ScheduledTaskEntity.class).forEach(this::addTriggerTask);
for(ScheduledTaskEntity task:taskList){
addTriggerTask(task);
}
} }
public void addTriggerTask(ScheduledTaskEntity scheduledTaskEntity) { public void addTriggerTask(ScheduledTaskEntity scheduledTaskEntity) {

@ -1,5 +1,3 @@
import db.annotation.BiliBili;
import db.util.ClassScaner;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -7,6 +5,6 @@ public class Test {
private static Logger log = LogManager.getLogger(); private static Logger log = LogManager.getLogger();
public static void main(String[] args) { public static void main(String[] args) {
ClassScaner.scan("db.model",BiliBili.class).forEach(aClass -> System.out.println(aClass));
} }
} }

Loading…
Cancel
Save