写一个自定义注解

@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. DotNetBar v12.4.0.2 Fully Cracked

    更新信息: http://www.devcomponents.com/customeronly/releasenotes.asp?p=dnbwf&v=12.4.0.2 如果遇到破解问题可以与我 ...

  2. yum源的更新问题

    我们知道在linux下安装软件的方法有多种多样,其中利用yum的方式来安装较为简单,但需要等待的时间比较长.下面介绍一下如何更新yum的源的问题. 首先需要保证的是linux的机器能上网.然后按照下面 ...

  3. table td的宽度详解

    前言:一直总觉得td的宽度好难驾驭,但万事万物总是有规律的.就像亮剑说的:不用因为怕八路就敬而远之,应该靠上去,熟悉他们,了解他们.   正文:           Table只有Table的宽度是可 ...

  4. hdu1394

    //Accepted 292 KB 46 ms //利用线段树求逆序数 //对于每个数看前面比他大的数有多少个,更新这个数的个数 #include <cstdio> #include &l ...

  5. 一个有趣的IE内核检测网站

    http://se.360.cn/v5/iecoretest.html 该网站能有效检测您浏览器的内核,以及版本,操作系统. 找到这个网址,是因为最近解决WebBrowser自动调节IE版本功能时发现 ...

  6. 03-树2 Tree Traversals Again

    这题是第二次做了,两次都不是独立完成,不过我发现我第一次参考的程序,也是参考老师(陈越)的范例做出来的.我对老师给的做了小幅修改,因为我不想有全局变量的的存在,所以我多传了三个参数进去.正序遍历每次都 ...

  7. 另类加载dll---快捷方式启动参数

    http://blogs.360.cn/360safe/2014/08/29/cnc_trojan_and_fake_proto/ 原文: BMP1和BMP2是两个lnk文件(快捷方式),我们知道bm ...

  8. jsunit测试

    var script = document.createElement('script'); script.src = 'http://static.pay.baidu.com/resource/ba ...

  9. (转) function与感叹号

    原文:http://blog.sina.com.cn/s/blog_775f158f01016j12.html function与感叹号(转)(2012-08-29 12:29:12) 最近有空可以让 ...

  10. HDU1556-color the ball(线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 #include<cstdio> using namespace std; stru ...