工作中遇到的问题--实现程序运行时就加载CustomerSetting的第二种方法
写一个自定义注解
@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface CurrentCustomerSettings {
}
在web初始化类中添加:
@Configuration
@Order(3)
@EnableWebMvcSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class MFGWebSecurityConfigurerAdapter extends
AWebSecurityConfigurerAdapter {
@Autowired
private UserRepository userRepository;
@Autowired
private CustomerSettingsRepository customerSettingsRepository;
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.formLogin()
.successHandler(
new SavedRequestAwareAuthenticationSuccessHandler())
.loginPage("/login").permitAll().failureUrl("/login-error")
.defaultSuccessUrl("/").and().logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/logged-out").permitAll().and().rememberMe()
.key(SECURITY_TOKEN)
.tokenRepository(persistentTokenRepository())
.tokenValiditySeconds(mfgSettings.getRememberMeTokenValidity())
.and().sessionManagement().maximumSessions(1)
.sessionRegistry(sessionRegistry).and().sessionFixation()
.migrateSession().and().authorizeRequests().anyRequest()
.authenticated();
}
@Bean
public PersistentTokenRepository persistentTokenRepository() {
JdbcTokenRepositoryImpl tokenRepository = new JdbcTokenRepositoryImpl();
tokenRepository.setDataSource(dataSource);
return tokenRepository;
}
@Bean
@LoggedInUser
@Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
@Transactional(readOnly = true)
public User getLoggedInUser() {
Authentication authentication = SecurityContextHolder.getContext()
.getAuthentication();
if (authentication != null
&& !(authentication instanceof AnonymousAuthenticationToken)
&& authentication.isAuthenticated())
return userRepository.findByLogin(authentication.getName());
return null;
}
@Bean
@SystemUser
@Scope(value = WebApplicationContext.SCOPE_APPLICATION, proxyMode = ScopedProxyMode.NO)
@Transactional(readOnly = true)
public User getSystemUser() {
return userRepository.findByLogin(Constants.SYSTEM_USER);
}
@Bean
@CurrentCustomerSettings
@Scope(value = WebApplicationContext.SCOPE_APPLICATION, proxyMode = ScopedProxyMode.NO)
public CustomerSettings customerSettings() {
return customerSettingsRepository.findAll().get(0);
}
以后在注入的时候,只需要写:
@CurrentCustomerSettings
@Autowired
CustomerSettings customerSettings;
工作中遇到的问题--实现程序运行时就加载CustomerSetting的第二种方法的更多相关文章
- 字节码编程,Javassist篇三《使用Javassist在运行时重新加载类「替换原方法输出不一样的结果」》
作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 通过前面两篇 javassist 的基本内容,大体介绍了:类池(ClassPool) ...
- Ubuntu中程序部署时无法加载动态库的解决方法
Ubuntu下修改环境变量的三种方法 添加环境变量无法解决,可尝试如下操作: sudo vim /etc/ld.so.conf 在ld.so.conf中加入动态库的目录... 然后 sudo ldco ...
- Eclipse运行时无法加载主类的解决方法
测试代码: package javastudy; class Person { public static void main(String[] args) { PersonCeshi pp=new ...
- 将DLL放入到资源中,运行时自动加载
今天在看到 一个小软件,考勤用的 AttendanceSheet_V_1_2,只有一个EXE文件,绿色的随便考到哪里都可以运行. 顺手反编译后发现,他将需要的DLL也放入到资源文件了,在启动的时候自动 ...
- eclipse中创建的spring-boot项目在启动时指定加载那一个配置文件的设置
步骤如下:鼠标点击项目右键—>Run As—>Run Configurations—>Java Application (如下图) 鼠标右键点击Java Application——— ...
- Java运行时动态加载类之ClassLoader
https://blog.csdn.net/fjssharpsword/article/details/64922083 *************************************** ...
- iframe中使用模态框提交表单后,iframe加载父页面的解决方法
在iframe中使用模态框提交表单后,会出现iframe加载整个父页面的问题,如下图: 解决方法: 在form表单中添加target属性 _parent 这个属性会使目标文档载入父窗口或者包含来超链接 ...
- 解决Eclipse中编辑xml文件的智能提示问题,最简单的是第二种方法。
Eclipse for Android xml 文件代码自动提示功能,介绍Eclipse 编辑器中实现xml 文件代码自动智能提示功能,解决eclipse 代码提示失效.eclipse 不能自动提示. ...
- SharpSvn 调用在运行时提示加载程序集出错,或有依赖项
策略后引用: SharpSvn, Version=1.8009.3299.43, Culture=neutral, PublicKeyToken=d729672594885a28日志: 尝试下载新的 ...
随机推荐
- Linux面试基础题-2
继续我们这面试系列,在这篇文章里我们给出了10个问题.这些问题或者是在以后的文章中出现的问题不一定在面试中会被问到.然而通过这些文章我们呈现出的是一个交互的学习平台,这必将会对你有很大的帮助. 自本系 ...
- Windows平台下的读写锁
Windows平台下的读写锁简单介绍Windows平台下的读写锁以及实现.背景介绍Windows在Vista 和 Server2008以后才开始提供读写锁API,即SRW系列函数(Initialize ...
- [转] C中的位域
一.位域 有些信息在存储时,并不需要占用一个完整的字节, 而只需占几个或一个二进制位.例如在存放一个开关量时,只有0和1 两种状态, 用一位二进位即可.为了节省存储空间,并使处理简便,C语言又提供了一 ...
- RPI学习--环境搭建_更新firmware
(用以解决USB摄像头不识别的状况) rpi-update是老外开发的一个更新树莓派firmware的工具 $ sudo apt-get update $ sudo apt-get install ...
- 《Java7中 下划线的新特性》
//Java7引入了一个新功能:程序员可以在数值中使用下画线,不管是 //整形数值,还是浮点型数值,都可以自由地使用下划线.通过下划线 //分隔,可以更直观的分辨数值中到底有多少位. public c ...
- poj2891 拓展欧几里得
//Accepted 164 KB 16 ms //拓展欧几里得 //m=a1*x+b1 --(1) //m=a2*(-y)+b2 --(2) //->a1*x+a2*y=b2-b1 //由欧几 ...
- URAL 1306 Sequence Median(优先队列)
题意:求一串数字里的中位数.内存为1M.每个数范围是0到2的31次方-1. 思路:很容易想到把数字全部读入,然后排序,但是会超内存.用计数排序但是数又太大.由于我们只需要第n/2.n/2+1大(n为偶 ...
- shell脚本入门教程(转)
http://bbs.chinaunix.net/thread-391751-1-1.html http://www.cnblogs.com/suyang/archive/2008/05/18/120 ...
- 数据库添加数据II及SQL语句错误
前些时候,写的代码(数据库添加数据I),往数据库添加数据都是很基本的一条一条地添加.但是平常用于测试时,总不可能一条一条地添加测试数据吧,然后我就尝试着一次性添加几百上千条,但是再次操作的时候,就出问 ...
- Math中floor,round和ceil的区别
floor 返回不大于的最大整数 round 则是4舍5入的计算,入的时候是到大于它的整数(当-1.5时可见,四舍五入后得到的结果不是我们期待的,解决办法是先对他取绝对值,然后在用round方法) r ...