写一个自定义注解

@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的第二种方法的更多相关文章

  1. 字节码编程,Javassist篇三《使用Javassist在运行时重新加载类「替换原方法输出不一样的结果」》

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 通过前面两篇 javassist 的基本内容,大体介绍了:类池(ClassPool) ...

  2. Ubuntu中程序部署时无法加载动态库的解决方法

    Ubuntu下修改环境变量的三种方法 添加环境变量无法解决,可尝试如下操作: sudo vim /etc/ld.so.conf 在ld.so.conf中加入动态库的目录... 然后 sudo ldco ...

  3. Eclipse运行时无法加载主类的解决方法

    测试代码: package javastudy; class Person { public static void main(String[] args) { PersonCeshi pp=new ...

  4. 将DLL放入到资源中,运行时自动加载

    今天在看到 一个小软件,考勤用的 AttendanceSheet_V_1_2,只有一个EXE文件,绿色的随便考到哪里都可以运行. 顺手反编译后发现,他将需要的DLL也放入到资源文件了,在启动的时候自动 ...

  5. eclipse中创建的spring-boot项目在启动时指定加载那一个配置文件的设置

    步骤如下:鼠标点击项目右键—>Run As—>Run Configurations—>Java Application (如下图) 鼠标右键点击Java Application——— ...

  6. Java运行时动态加载类之ClassLoader

    https://blog.csdn.net/fjssharpsword/article/details/64922083 *************************************** ...

  7. iframe中使用模态框提交表单后,iframe加载父页面的解决方法

    在iframe中使用模态框提交表单后,会出现iframe加载整个父页面的问题,如下图: 解决方法: 在form表单中添加target属性 _parent 这个属性会使目标文档载入父窗口或者包含来超链接 ...

  8. 解决Eclipse中编辑xml文件的智能提示问题,最简单的是第二种方法。

    Eclipse for Android xml 文件代码自动提示功能,介绍Eclipse 编辑器中实现xml 文件代码自动智能提示功能,解决eclipse 代码提示失效.eclipse 不能自动提示. ...

  9. SharpSvn 调用在运行时提示加载程序集出错,或有依赖项

    策略后引用: SharpSvn, Version=1.8009.3299.43, Culture=neutral, PublicKeyToken=d729672594885a28日志: 尝试下载新的 ...

随机推荐

  1. 编译哈工大语言技术平台云LTP(C++)源码及LTP4J(Java)源码

    转自:编译哈工大语言技术平台云LTP(C++)源码及LTP4J(Java)源码 JDK:java version “1.8.0_31”Java(TM) SE Runtime Environment ( ...

  2. 新浪微博数据抓取(java实现)

    多了不说,直接贴出相关部分的实现代码 加密部分实现: package token.exe; import java.math.BigInteger; import java.util.Random; ...

  3. Linux摄像头驱动学习之:(二)通过虚拟驱动vivi分析摄像头驱动

    一.通过指令 "strace -o xawtv.log xawtv" 得到以下调用信息:// 1~7都是在v4l2_open里调用1. open2. ioctl(4, VIDIOC ...

  4. (转载)Htmlparser Filter 简要归纳

    1 . 逻辑关系:与或非 AndFilter()           Creates a new instance of an AndFilter. AndFilter(NodeFilter[] pr ...

  5. 【SQL查询日志】查看数据库历史查询记录

    --关键字:cross apply & outer apply --最后更新:2011-10-20 作者:Ronli--更新链接:http://www.cnblogs.com/ronli/ar ...

  6. php的数据访问

    方法一:过去时方法 $定义一个变量 = $mysql_connect("要连接的服务器,默认是 localhost","登录所使用的用户名,默认是 root", ...

  7. PAT 05-树7 File Transfer

    这次的题让我对选择不同数据结构所产生的结果惊呆了,一开始用的是结构来存储集合,课件上有现成的,而且我也是实在不太会,150ms的时间限制过不去,不得已,看到这题刚好可以用数组,结果7ms最多,有意思! ...

  8. c规范(2)

    一:对齐 1 程序的分界符' {'和' }'应独占一行并且位于同一列,同时与引用它们的语句左对齐. 2  { }之内的代码块在' {'右边数格处左对齐. 二:注释 注释通常用于:( 1)版本.版权声明 ...

  9. powershell命令大全

    Name Category Synopsis ---- -------- -------- ac Alias Add-Content asnp Alias Add-PSSnapin clc Alias ...

  10. 团队开发——冲刺1.a

    冲刺阶段一(第一天) 1.今天准备做什么? 在了解C#的基础上,深入熟悉Windows窗体应用程序,熟练掌握基本功能. 2.明天做什么:简单设计界面.