Github项目学习

newbee-mall

  • WebMvcConfigurationSupport和WebMvcCofigurer的区别

    SpringBoot2.0之后WebMvcConfigurerAdapter过时,取而代之的是WebMvcConfigurationSupport

    查看源码发现: WebMvcConfigurerAdapter只是对WebMvcCofigurer的空实现,而WebMvcConfigurationSupport的实现的方法更全面。但是继承WebMvcConfigurationSupport会发现Spring Boot的WebMvc自动配置失效(WebMvcAutoConfiguration自动化配置),导致无法视图解析器无法解析并返回到对应的视图

    WebMvcConfigurationSupport–>不需要返回逻辑视图,可以选择继承此类

    WebMvcCofigurer–>返回逻辑视图,可以选择实现此方法

forum-java

forum-starter

  • SpringBootServletInitializer是一个支持Spring Boot的Spring WebApplicationInitializer实现。除了配置Spring的Dispatcher-Servlet, SpringBootServletInitializer还会在Spring应用程序上下文里查找Filter、Servlet或ServletContextInitializer类型的Bean,把它们绑定到Servlet容器里。要使用SpringBootServletInitializer,只需创建一个子类,覆盖configure()方法来指定Spring配置类。

    @EnableScheduling
    @SpringBootApplication(scanBasePackages = "pub.developers.forum")
    @MapperScan(value = {"pub.developers.forum.infrastructure.dal.dao"})
    public class ForumJavaApplication extends SpringBootServletInitializer {
    
    	public static void main(String[] args) {
    		SpringApplication.run(ForumJavaApplication.class, args);
    	}
    
    	@Override
    	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    		return builder.sources(ForumJavaApplication.class);
    	}
    }
    
  • @EnableScheduling 注解对应的内容如下:

    @Target(ElementType.TYPE)
    @Retention(RetentionPolicy.RUNTIME)
    @Import(SchedulingConfiguration.class)
    @Documented
    public @interface EnableScheduling {
    
    }
    

    由上可以看到实际上是SchedulingConfiguration.class 类实现了Spring 的任务调度框架级功能。该配置类仅仅是定义了ScheduledAnnotationBeanPostProcessor 的实例。Spring 的调度功能由该实例进行配置。

    定时任务在配置类上添加@EnableScheduling开启对定时任务的支持,在相应的方法上添加@Scheduled声明需要执行的定时任务。

    @Scheduled @Scheduled注解各参数详解

  • MyTest.java

  • pom.xml spring-boot-maven-plugin

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
            <!--SpringBoot 2.5.3在打包的时候已经排除processor(用于自定义属性的提示),不需要添加插件-->
            <excludes>
                <exclude>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-configuration-processor</artifactId>
                </exclude>
            </excludes>
        </configuration>
        <!-- mvn spring-boot:repackage -->
        <executions>
            <execution>
                <goals>
                    <goal>repackage</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

forum-domain

forum-common

  • package pub.developers.forum.common.model

    • PageRequest
    • PageResult
  • package pub.developers.forum.common.support

forum-infrastructure

  • package pub.developers.forum.infrastructure.audit

    • PostsAuditTask
  • package pub.developers.forum.infrastructure.cache

    • DbCacheServiceImpl
  • package pub.developers.forum.infrastructure.file

    • QiNiuFileServiceImpl
  • package pub.developers.forum.infrastructure.github

  • package pub.developers.forum.infrastructure.mail

    • Mail163ServiceImpl

      <dependency>
          <groupId>com.sun.mail</groupId>
          <artifactId>javax.mail</artifactId>
          <version>1.6.2</version>
      </dependency>
      
  • package pub.developers.forum.infrastructure.search

    • DbSearchServiceImpl
  • package pub.developers.forum.infrastructure.transfer

    • PostsTransfer 利用继承对各种方法的抽取
  • pom.xml

    <!--添加编译参数-->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
            <compilerArgs>
                <arg>--add-exports</arg>
                <arg>java.base/com.sun.net.ssl.internal.ssl=ALL-UNNAMED</arg>
            </compilerArgs>
        </configuration>
    </plugin>
    

forum-api

  • package pub.developers.forum.api.model
    • PageRequestModel @Setter的使用

forum-app

  • package pub.developers.forum.app.support
    • IsLoginAspect
    • LoginUserContext
  • package pub.developers.forum.app.manager

forum-facade

  • package pub.developers.forum.facade.aspect

    • ExceptionHandlerAndLogAspect
    • LoginUserAspect

    只会代理在容器中的组件,在本项目中,虽然匹配的是api包下的所有包的所有类的所有方法,但只有service包下接口的实现类在容器中,所以实际代理的是所有实现类的方法

forum-portal

  • package pub.developers.forum.portal.support

    • CorsInterceptor
    • GlobalViewInterceptor
    • GetMappingAspect
    • ResponseBodyAspect
    • WebConfigurer
    • WebContext
  • @Value注解

    • WebUtil
  • Java8 函数式接口

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值