Spring

Difference between ExitCodeGenerator and System.exit(0)

烂漫一生 提交于 2021-02-10 12:17:06
问题 I recently learned that the proper way to shut down a Spring Boot application is this: public class Application { @Bean public ExitCodeGenerator exitCodeGenerator() { return new ExitCodeGenerator() { @Override public int getExitCode() { return 0; } }; } public static void main(String[] args) throws Exception { System.exit(SpringApplication.exit(SpringApplication.run(Application.class, args))); } } This should return an exit code of 0, or whatever I configure it to return in the getExitCode()

Configure Spring Security for multiple login pages in a Spring Boot application

末鹿安然 提交于 2021-02-10 11:53:19
问题 @Configuration public class SpringSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private AccessDeniedHandler accessDeniedHandler; @Override protected void configure(HttpSecurity http) throws Exception { http.csrf().disable() .authorizeRequests() .antMatchers("/", "/home", "/about").permitAll() .antMatchers("/admin/**").hasAnyRole("ADMIN") .antMatchers("/user/**").hasAnyRole("USER") .anyRequest().authenticated() .and() .formLogin() .loginPage("/login") .permitAll() .and()

Configure Spring Security for multiple login pages in a Spring Boot application

旧巷老猫 提交于 2021-02-10 11:50:06
问题 @Configuration public class SpringSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private AccessDeniedHandler accessDeniedHandler; @Override protected void configure(HttpSecurity http) throws Exception { http.csrf().disable() .authorizeRequests() .antMatchers("/", "/home", "/about").permitAll() .antMatchers("/admin/**").hasAnyRole("ADMIN") .antMatchers("/user/**").hasAnyRole("USER") .anyRequest().authenticated() .and() .formLogin() .loginPage("/login") .permitAll() .and()

Java项目笔记之旅游点评项目总结03

末鹿安然 提交于 2021-02-10 09:49:39
不点蓝字,我们哪来故事? 游记: 游记是用户自己发表的。由用户自己管理,管理人员只负责审核和发布; 需求:查看和拒绝 用户的文章由前端用户自己维护,管理仅仅显示和对状态进行管理,不能进行添加编辑操作; 查看是前台只需要游记的内容即可,后台将游记的内容反给前台。根据当前游记的id查到游记对象,在从游记对象中 getContent() 返回即可; 审核状态: 审核逻辑 :游记满足什么条件才进行审核,审核通过和审核不通过分别需要做什么操作? 审核通过是发布状态; 只对状态是待审核的游记才进行审核; 审核通过/拒绝将游记的状态改成审核通过/审核拒绝; 审核通过之后还需要改变游记的发布时间和最后修改时间; 用户修改内容之后,需要考虑那些统计数据(点赞阅读等)要不要清空(问你的产品经理); //审核游记 @ Override public void changeState ( String id, int state ) throws LoadException { //满足什么条件才进行审核 //查询游记 Optional<Travel> optional = repository.findById(id); if (!optional.isPresent() && state != Travel.STATE_WAITING) { //有内容并且状态是待审核的才审核,否则抛异常 throw

Logback configuration to mask specific log data

廉价感情. 提交于 2021-02-10 09:38:47
问题 I have a Spring Boot web app and am using logback as my logging solution. I have been looking through the documentation and cannot find an easy or 'correct' way to mask private/specific data (Personal info, credit card #s, etc.). The closest I have been able to find is Logback filters, however the use case around those seems to be more about omitting logs that match specific criteria, I am simply looking to mask all, application wide, logs. This seems like such a basic question and I am

Cas no attributes come to client

限于喜欢 提交于 2021-02-10 09:35:31
问题 i am building SSO application with CAS. in spring client, no attributes came with CasAssertionAuthenticationToken . there are lots of samples on net, they seems to have no problem with this ( is something obvious missing?) for cas server, its all default configuration except i changed registered service default to make sure that is not the problem. this part look like this: <bean class="org.jasig.cas.services.RegexRegisteredService"> <property name="id" value="1"/> <property name="name" value

Cas no attributes come to client

蹲街弑〆低调 提交于 2021-02-10 09:34:46
问题 i am building SSO application with CAS. in spring client, no attributes came with CasAssertionAuthenticationToken . there are lots of samples on net, they seems to have no problem with this ( is something obvious missing?) for cas server, its all default configuration except i changed registered service default to make sure that is not the problem. this part look like this: <bean class="org.jasig.cas.services.RegexRegisteredService"> <property name="id" value="1"/> <property name="name" value

Cas no attributes come to client

≯℡__Kan透↙ 提交于 2021-02-10 09:34:25
问题 i am building SSO application with CAS. in spring client, no attributes came with CasAssertionAuthenticationToken . there are lots of samples on net, they seems to have no problem with this ( is something obvious missing?) for cas server, its all default configuration except i changed registered service default to make sure that is not the problem. this part look like this: <bean class="org.jasig.cas.services.RegexRegisteredService"> <property name="id" value="1"/> <property name="name" value

Spring Data - MongoDB - JUnit test

点点圈 提交于 2021-02-10 09:33:06
问题 I would have a question concerning Spring Data - MongoDB and JUnit test. @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = { UserRepository.class, User.class }) public class MyJUnitTest { The UserRepository looks like this: @Repository public interface UserRepository extends MongoRepository<User, String> { User findByUsername(final String username); } I get the following Exception: Failed to instantiate [... .repository.UserRepository]: Specified class is an

SpringBoot是如何加载配置文件的?

 ̄綄美尐妖づ 提交于 2021-02-10 08:59:26
前言 本文针对版本 2.2.0.RELEASE 来分析SpringBoot的配置处理源码,通过查看SpringBoot的源码来弄清楚一些常见的问题比如: SpringBoot从哪里开始加载配置文件? SpringBoot从哪些地方加载配置文件? SpringBoot是如何支持 yaml 和 properties 类型的配置文件? 如果要支持 json 配置应该如何做? SpringBoot的配置优先级是怎么样的? placeholder是如何被解析的? 带着我们的问题一起去看一下SpringBoot配置相关的源代码,找出问题的答案。 SpringBoot从哪里开始加载配置文件? SpringBoot加载配置文件的入口是由 ApplicationEnvironmentPreparedEvent 事件进入的,SpringBoot会在SpringApplication的构造函数中通过 spring.factories 文件获取ApplicationListener的实例类: public SpringApplication(ResourceLoader resourceLoader, Class<?>... primarySources) { ... setListeners((Collection) getSpringFactoriesInstances