写一个自定义注解

@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. 编写一个小Servlet程序

    1.编写一个java类,此类继承HttpServlet 创建完工程(见上一篇随笔:使用eclipse创建在myeclipse中运行的web工程),在src中新建一个包,包名字叫servlet:再新建一 ...

  2. 恢复drop数据

    select * from recyclebin r where r.original_name = 'MSM_EXAINVITEBIDSCHEMEHEAD' ; flashback table MS ...

  3. vue js 用nodejs的依赖包 --2016-08-23

     今天被nodejs包依赖坑了一下,上次上传的项目突然运行不起来了,原来是package.json中定义了使用最新版本的依赖,而最新版本有可能调整了结构或者改了api,比如vux把flexbox-it ...

  4. SQL语句查询所耗时间与效能的语句

    1)SQL查询所耗时间语句 原理:记录当前时间1,执行SQL语句,记录当前时间2,显示时间2与时间1的差. 由于第一次执行的所耗时间为真实时间,之后会保存在缓存中,所以第二次之后的查询所耗时间都会比第 ...

  5. hdu1394

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

  6. Ubuntu 14.10 下设置时间同步

    在启动HBase机群的时候,发现了一个错误,因为机群时间不同步导致,所以要同步集群时间. Linux的时间分为System Clock(系统时间)和Real Time Clock (硬件时间,简称RT ...

  7. My_Python的常用函数.

    范围生成函数 class range(object) | range(stop) -> range object | range(start, stop[, step]) -> range ...

  8. python3爬虫初探(五)之从爬取到保存

    想一想,还是写个完整的代码,总结一下前面学的吧. import requests import re # 获取网页源码 url = 'http://www.ivsky.com/tupian/xiaoh ...

  9. iOS System Services

    System Services is a singleton class to gather all available information about a device. Over 75 met ...

  10. Android Studio, gradle plugin is too old or set ANDROID_DAILY_OVERRIDE

    早上打开Android Studio,忽然报了个错,说gradle plugin版本过低,让更新或者设置ANDROID_DAILY_OVERRIDE环境变量: 日志如下: INFO - ls.idea ...