spring source code 5 Import idea2019 three point five

prepare

  • Download idea2019 3.5 install and activate (see the compressed package sent by brother chicken in the group for specific steps).

  • Pull spring 5 3.5 source code (tips: it is recommended to start with Star and then Forked, and then go back to the project warehouse of your account and then pull): https://gitee.com/hhf1237/spring-framework

  • Download jdk15 and unzip: https://pan.baidu.com/s/1m8gwlKJ818Q6sjvZPSg9iQ Extraction code: tm9n (tips: jdk 11 and above are ok). You don't need to configure environment variables, just keep your jdk8.

  • Download gradle, version: gradle-6.4-rc-4: https://services.gradle.org/distributions/ (tips: the gradle version should be between 5.6 and 6.5, which can be consistent with me). Configure the environment variable (variable name: GRADLE_HOME).

  • Check the environment variable: gradle -v

  • Configure acceleration (optional)

    • Gradle's jar package was also downloaded from maven warehouse.

    • Install init. In the gradle installation directory D folder, put an init Gradle file (copy and paste in, remember to save).

      gradle.projectsLoaded {
          rootProject.allprojects {
              buildscript {
                  repositories {
                      def JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
                      def GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
                      def NEXUS_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
                      all { ArtifactRepository repo ->
                          if (repo instanceof MavenArtifactRepository) {
                              def url = repo.url.toString()
                              if (url.startsWith('https://jcenter.bintray.com/')) {
                                  project.logger.lifecycle "Repository ${repo.url} replaced by $JCENTER_URL."
                                  println("buildscript ${repo.url} replaced by $JCENTER_URL.")
                                  remove repo
                              }
                              else if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
                                  project.logger.lifecycle "Repository ${repo.url} replaced by $GOOGLE_URL."
                                  println("buildscript ${repo.url} replaced by $GOOGLE_URL.")
                                  remove repo
                              }
                              else if (url.startsWith('https://repo1.maven.org/maven2')) {
                                  project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
                                  println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
                                  remove repo
                              }
                          }
                      }
                      jcenter {
                          url JCENTER_URL
                      }
                      google {
                          url GOOGLE_URL
                      }
                      maven {
                          url NEXUS_URL
                      }
                  }
              }
              repositories {
                  def JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
                  def GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
                  def NEXUS_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
                  all { ArtifactRepository repo ->
                      if (repo instanceof MavenArtifactRepository) {
                          def url = repo.url.toString()
                          if (url.startsWith('https://jcenter.bintray.com/')) {
                              project.logger.lifecycle "Repository ${repo.url} replaced by $JCENTER_URL."
                              println("buildscript ${repo.url} replaced by $JCENTER_URL.")
                              remove repo
                          }
                          else if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
                              project.logger.lifecycle "Repository ${repo.url} replaced by $GOOGLE_URL."
                              println("buildscript ${repo.url} replaced by $GOOGLE_URL.")
                              remove repo
                          }
                          else if (url.startsWith('https://repo1.maven.org/maven2')) {
                              project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
                              println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
                              remove repo
                          }
                      }
                  }
                  jcenter {
                      url JCENTER_URL
                  }
                  google {
                      url GOOGLE_URL
                  }
                  maven {
                      url NEXUS_URL
                  }
              }
          }
      }
      

start

import source code

  • Modify the configuration to: distributionUrl=https://services.gradle.org/distributions/gradle-6.4-rc-4-bin.zip (tips: modify according to the gradle version. Remember to save and configure the environment variable).

  • Open idea2019 3.5. Open an existing project casually.

  • File->New->Project from Existing Sources...

  • Find the file location of the source code and select the top-level build Gradle, the top-level build Gradle, the top-level build Gradle (say something important three times).

  • Click: This Window or New Window, you can also click Cancel completely, and then there will be a loaded window. Click Cancel immediately, click Cancel immediately, and click Cancel immediately (important things need to be said three times).

  • Set gradle and jdk of idea (see the figure for specific operation)

  • Build (see the figure for specific operation)

  • wait...

    • It is suggested to have a meal and flirt with your sister.
  • import success

  • Setting up Java Compiler

  • Set project SDK

  • Modify the spring context module configuration

    dependencies {
    	compile(project(":spring-aop"))
    	compile(project(":spring-beans"))
    	compile(project(":spring-core"))
    	compile(project(":spring-expression"))
    //	optional(project(":spring-instrument"))
    	compile(project(":spring-instrument"))
        ....
    }
    

  • Precompiled spring core module

  • compiler success

  • Add dependency

  • Create a test module

    • The project name, path and other information will be handled by yourself, and then click Finish to start.
  • Add dependency

  • Do whatever you want with the rest of the spring. I don't understand. It's recommended to click the X in the upper right corner. Bye.

aop

  • First, confirm that there are relevant jar package dependencies in the figure below. By default, there will be automatically after precompiling the spring core module. If there is no need to add manually, the method of adding will be described below.

    If there is no jar dependency, you need to add it manually:

  • Download and install AspectJ support: https://www.eclipse.org/aspectj/downloads.php

    • Download AspectJ 1.9.5

    • Use the cmd command to cd to the downloaded directory

    • In the command window, enter Java - jar aspectj-1.9.5 Jar installation

    • Select the root directory of the jdk where we need to compile the spring source code

    • Installation directory of AspectJ (remember the location, which will be used later)

    • Install AspectJ plug-in in idea, and restart idea after successful installation.

    • Change compiler

    • Add AspectJ to the main of spring AOP and spring aspects

    • Build again (don't worry about stupid kt errors)

    • Create an aop test module, add dependencies, refresh and load the module.

      dependencies {
          compile(project(":spring-context"))
          compile(project(":spring-aspects"))
      }
      

    • The rest of the spring aop can be used as you like. If you don't understand, it's recommended to click the X in the upper right corner. Bye.

transaction

  • Create a new module and add dependencies

    dependencies {
        compile(project(":spring-context"))
        compile(project(":spring-jdbc"))
    
        implementation group: 'mysql', name: 'mysql-connector-java', version: '5.1.49'
        implementation group: 'com.alibaba', name: 'druid', version: '1.2.8'
        testCompile group: 'junit', name: 'junit', version: '4.12'
    }
    

  • Configuration class

    package com.qqs.tx;
    
    import com.alibaba.druid.pool.DruidDataSource;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.jdbc.core.JdbcTemplate;
    import org.springframework.jdbc.datasource.DataSourceTransactionManager;
    import org.springframework.transaction.PlatformTransactionManager;
    import org.springframework.transaction.annotation.EnableTransactionManagement;
    
    import javax.sql.DataSource;
    
    @Configuration
    @ComponentScan("com.qqs.tx")
    @EnableTransactionManagement
    public class TxConfiguration {
    	/**
    	 * Configure the data source (account, password and url are self configured)
    	 * @return
    	 */
    	@Bean
    	public DataSource dataSource(){
    		DruidDataSource dataSource = new DruidDataSource();
    		dataSource.setUsername("admin");
    		dataSource.setPassword("admin");
    		dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    		dataSource.setUrl("jdbc:mysql://localhost:3306/spring");
    		return dataSource;
    	}
    
    	@Bean
    	public JdbcTemplate jdbcTemplate(){
    		return new JdbcTemplate(dataSource());
    	}
    
    	/**
    	 * Configure transaction manager
    	 * @return
    	 */
    	@Bean
    	public PlatformTransactionManager transactionManager(){
    		return new DataSourceTransactionManager(dataSource());
    	}
    }
    
    

    Note: mysql version is 5.7. If it is mysql 8.0 0 please refer to the information and configure the url parameter by yourself.

  • The rest of the business classes are handled by themselves. If you don't understand, it is recommended to click the X in the upper right corner. Bye.

web

  • Create a new module and add dependencies.

    compile(project(":spring-webmvc"))
    optional group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
    

  • Root container configuration class

    @Configuration
    @ComponentScan(value = "com.qqs.mvc",excludeFilters = {
    		@ComponentScan.Filter(type = FilterType.ANNOTATION,classes = {Controller.class})
    })
    public class RootConfiguration {
    }
    
  • web ioc container configuration class

    @Configuration
    @ComponentScan(value = {"com.qqs.mvc"},includeFilters = {
    		@ComponentScan.Filter(type = FilterType.ANNOTATION,classes = {Controller.class})
    },useDefaultFilters = false)
    public class AppConfiguration {
    }
    
  • WebAppInitializer

    package com.qqs.mvc;
    
    import com.qqs.mvc.config.AppConfiguration;
    import com.qqs.mvc.config.RootConfiguration;
    import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
    
    public class MyWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
    	/**
    	 * Gets the configuration class of the root container
    	 * @return
    	 */
    	@Override
    	protected Class<?>[] getRootConfigClasses() {
    		return new Class[]{RootConfiguration.class};
    	}
    
    	/**
    	 * Get the configuration class of the web container
    	 * @return
    	 */
    	@Override
    	protected Class<?>[] getServletConfigClasses() {
    		return new Class[]{AppConfiguration.class};
    	}
    
    	/**
    	 * Get the mapping information of DispatcherServlet
    	 * @return
    	 */
    	@Override
    	protected String[] getServletMappings() {
    		return new String[]{"/"};
    	}
    }
    
  • WebMvcConfigurer (spring MVC custom configuration function)

    package com.qqs.mvc.config;
    
    // import com.qqs.mvc.Interceptor.MyHandlerInterceptor;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.servlet.config.annotation.*;
    
    @EnableWebMvc // Enable the spring MVC custom configuration function
    @Configuration
    public class MyWebMvcConfigurer implements WebMvcConfigurer {
    	@Override
    	public void configureViewResolvers(ViewResolverRegistry registry) {
    		// Default JSP without parameters ("/ WEB-INF /,". JSP ")
    		registry.jsp("/WEB-INF/views/",".jsp");
    	}
    
    	@Override
    	public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
    		// Static resources
    		configurer.enable();
    	}
    
    	@Override
    	public void addInterceptors(InterceptorRegistry registry) {
    		// Configuring Interceptors 
    		// registry.addInterceptor(new MyHandlerInterceptor()).addPathPatterns("/**");
    	}
    }
    
  • Business classes and tomcat can be done as they were before they were run. Please don't Baidu yourself.

hole

  • one

    • Error message:

      Information:java: com.sun.tools.javac.code.Symbol$CompletionFailure: can't find jdk.internal.HotSpotIntrinsicCandidate Class file for
      Information:java: Errors occurred while compiling module 'spring.spring-core.main'
      Information:javac 15.0.2 was used to compile java sources
      Information:Modules "spring.spring-ioc-test.main", "spring.spring-core.main" were fully rebuilt due to project configuration/dependencies changes
      Information:2022/2/23 13:57 - Build completed with 1 error and 0 warnings in 10 s 892 ms
      Error:java: Compilation failed: internal java compiler error
      

    • Cause analysis: there is a problem with the configuration of jdk.

    • Solution: switch to other jdk versions, click ok, and then switch back

  • two

    • Error message:

      Error:(19, 15) java: Package jdk.jfr non-existent
      

    • Cause analysis: there are no relevant classes in the currently compiled jdk version.

    • Solution: modify the version of java compiler in idea.

  • three

    • Error message:

      Error:ajc: Compliance level '1.8' is incompatible with target level '11'. A compliance level '11' or better is required
      Error:Internal error: bad args
      
    • Cause analysis: the jdk version of java compiler is inconsistent with that of project.

    • Solution: modify the version of java compiler and project.

  • four

    • Error message:

      Error:(19, 49) java: Symbol not found
        Symbol:   class AnnotationBeanConfigurerAspect
        position: Package org.springframework.beans.factory.aspectj
      Error:(47, 16) java: Symbol not found
        Symbol:   class AnnotationBeanConfigurerAspect
        position: class org.springframework.context.annotation.aspectj.SpringConfiguredConfiguration
      Error:(48, 24) java: Symbol not found
        Symbol:   variable AnnotationBeanConfigurerAspect
        position: class org.springframework.context.annotation.aspectj.SpringConfiguredConfiguration
      D:\workspace\spring-framework-5.1.x\spring-aspects\src\main\java\org\springframework\cache\aspectj\AspectJJCacheConfiguration.java
      Error:(42, 16) java: Symbol not found
        Symbol:   class JCacheCacheAspect
        position: class org.springframework.cache.aspectj.AspectJJCacheConfiguration
      Error:(43, 17) java: Symbol not found
        Symbol:   class JCacheCacheAspect
        position: class org.springframework.cache.aspectj.AspectJJCacheConfiguration
      Error:(43, 49) java: Symbol not found
        Symbol:   variable JCacheCacheAspect
        position: class org.springframework.cache.aspectj.AspectJJCacheConfiguration
      D:\workspace\spring-framework-5.1.x\spring-aspects\src\main\java\org\springframework\scheduling\aspectj\AspectJAsyncConfiguration.java
      Error:(43, 16) java: Symbol not found
        Symbol:   class AnnotationAsyncExecutionAspect
        position: class org.springframework.scheduling.aspectj.AspectJAsyncConfiguration
      Error:(44, 17) java: Symbol not found
        Symbol:   class AnnotationAsyncExecutionAspect
        position: class org.springframework.scheduling.aspectj.AspectJAsyncConfiguration
      Error:(44, 62) java: Symbol not found
        Symbol:   variable AnnotationAsyncExecutionAspect
        position: class org.springframework.scheduling.aspectj.AspectJAsyncConfiguration
      D:\workspace\spring-framework-5.1.x\spring-aspects\src\main\java\org\springframework\cache\aspectj\AspectJCachingConfiguration.java
      Error:(42, 16) java: Symbol not found
        Symbol:   class AnnotationCacheAspect
        position: class org.springframework.cache.aspectj.AspectJCachingConfiguration
      Error:(43, 17) java: Symbol not found
        Symbol:   class AnnotationCacheAspect
        position: class org.springframework.cache.aspectj.AspectJCachingConfiguration
      Error:(43, 53) java: Symbol not found
        Symbol:   variable AnnotationCacheAspect
        position: class org.springframework.cache.aspectj.AspectJCachingConfiguration
      D:\workspace\spring-framework-5.1.x\spring-aspects\src\main\java\org\springframework\transaction\aspectj\AspectJTransactionManagementConfiguration.java
      Error:(42, 16) java: Symbol not found
        Symbol:   class AnnotationTransactionAspect
        position: class org.springframework.transaction.aspectj.AspectJTransactionManagementConfiguration
      Error:(43, 17) java: Symbol not found
        Symbol:   class AnnotationTransactionAspect
        position: class org.springframework.transaction.aspectj.AspectJTransactionManagementConfiguration
      Error:(43, 56) java: Symbol not found
        Symbol:   variable AnnotationTransactionAspect
        position: class org.springframework.transaction.aspectj.AspectJTransactionManagementConfiguration
      
    • Cause analysis: AOP of spring source code uses aspectJ, while java does not recognize aspectJ.

    • Solution: refer to the aop configuration process and reconfigure it again.

  • five

    • Error message:

      Error:(36, 41) java: Package org.springframework.oxm.jaxb.test non-existent
      Error:(37, 41) java: Package org.springframework.oxm.jaxb.test non-existent
      Error:(65, 17) java: Symbol not found
        Symbol:   class Flights
        position: class org.springframework.oxm.jaxb.Jaxb2UnmarshallerTests
      Error:(65, 36) java: Symbol not found
        Symbol:   class Flights
        position: class org.springframework.oxm.jaxb.Jaxb2UnmarshallerTests
      Error:(73, 17) java: Symbol not found
        Symbol:   class FlightType
        position: class org.springframework.oxm.jaxb.Jaxb2UnmarshallerTests
      
    • Cause analysis: jaxb package under spring oxm module does not exist.

    • Solution: rebuild the spring oxm module to JAXB

remark

  • The final code of this tutorial: https://gitee.com/qqs12487489/spring
  • reference resources: https://blog.csdn.net/qq_38196479/article/details/104071904
  • Still awesome! Chicken, cow!
    ts
    Location: class org springframework. oxm. jaxb. Jaxb2UnmarshallerTests
    Error:(65, 36) java: symbol not found
    Symbols: class Flights
    Location: class org springframework. oxm. jaxb. Jaxb2UnmarshallerTests
    Error:(73, 17) java: symbol not found
    Symbols: class FlightType
    Location: class org springframework. oxm. jaxb. Jaxb2UnmarshallerTests
    * Cause analysis: spring-oxm Under module jaxb Package does not exist.
    
    * resolvent: spring-oxm Module re genJaxb
    
    [External chain picture transfer...(img-bpQ3iOkz-1645612538271)]
    
    

remark

  • The final code of this tutorial: https://gitee.com/qqs12487489/spring
  • reference resources: https://blog.csdn.net/qq_38196479/article/details/104071904
  • Still awesome! Chicken, cow!

Keywords: Java Spring

Added by mc2007 on Wed, 23 Feb 2022 14:58:09 +0200