工作中遇到的问题--实现程序运行时就加载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日志: 尝试下载新的 ...
随机推荐
- C/C++文件结构
总结者:kate (1).h 为头文件:存放 版权和版本声明,预处理块 ,函数和类结构声明 (2).cpp文件:代码文件,存放程序的实现 大都数时候,源文件和头文件是对应出现的,比如有一个A.cpp ...
- 使用JsonObject解析json
第一种: [ { "0": "1", "1": "一", "id": "1", ...
- 创建MySQL数据库和表(一)
一.启动MySQL服务 1.在Windows操作系统的“服务”中启动,找到你安装MySQL的起的服务名称,我本机服务名的是MySQL. 2.在命令行中用命令启动: A.启动MySQL服务:net st ...
- OBJECT ARX 添加标注样式
////获得当前图形的标注样式表 AcDbDimStyleTable* pDimStyleTbl; acdbHostApplicationServices()->workingDatabase( ...
- hdu 2068
ps:长度长到我不想说....WA了无数次...25的阶乘就爆炸... 代码: #include "stdio.h" #define LL long long LL fac(lon ...
- 多比Web 3D展示(3D机房/3D监控)中间件多比Web 3D展示(3D机房/3D监控)中间件免费下载购买地址
多比3D是实现3D场景搭建的软件开发包,可以创建广泛的3D应用,适用于高端制造.能源.国防军工.教育科研.城市规划及建筑环艺.生物医学等领域的虚拟仿真,应用于虚拟展示.虚拟设计.方案评审.虚拟装配.虚 ...
- 解决办法:在指定的 DSN 中,驱动程序和应用程序之间的体系结构不匹配 问题解决 SQLSTATE=IM014
环境:64位win7,64位MySql 解决办法:32为和64位ODBC都安装上即可.
- 我与python3擦肩而过(一)—— Dict与collections.OrderredDict邂逅
最近一直在撸Python Data Analysis上的代码(书是基于Python2的,小白我用的python3),所以我下的时候多少有些改动. 这是9.4中的nltk词频分析关于Dict_key的问 ...
- swift SDWebImage使用
Web image(网络图像) 该库提供了一个支持来自Web的远程图像的UIImageView类别它提供了: 添加网络图像和缓存管理到Cocoa Touch framework的UIImageView ...
- Mac快捷键 Xcode快捷键
Mac OSX 快捷键&命令行 一.Mac OSX 快捷键 ctrl+shift 快速放大dock的图标会暂时放大,而 ...