我试图从Spring Security留档中重复,并试图保护一个网页作为测试。我严格按照Spring编写的留档做所有事情。
Spring文档-1
Spring文档-2
Spring文档-3
但它不起作用。我已经被这个问题折磨了7天。我快疯了。我不知道该怎么办,如何克服这个错误。它发生在项目的组装阶段。谁能帮忙请。
这里是错误日志:
C:\TomCat\apache-tomcat-9.0.30\bin\catalina.bat run [2020-02-22 12:42:59,722] Artifact ConcretePage:war exploded: Waiting for server connection to start artifact deployment... Using CATALINA_BASE: "C:\Users\ѓҐ ¤Ё©\.IntelliJIdea2019.3\system\tomcat\Unnamed_ConcretePage_2" Using CATALINA_HOME: "C:\TomCat\apache-tomcat-9.0.30" Using CATALINA_TMPDIR: "C:\TomCat\apache-tomcat-9.0.30\temp" Using JRE_HOME: "C:\Program Files\Java\jdk1.8.0_241" Using CLASSPATH: "C:\TomCat\apache-tomcat-9.0.30\bin\bootstrap.jar;C:\TomCat\apache-tomcat-9.0.30\bin\tomcat-juli.jar" 22-Feb-2020 00:43:01.416 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/9.0.30 22-Feb-2020 00:43:01.418 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Dec 7 2019 16:42:04 UTC 22-Feb-2020 00:43:01.418 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.30.0 22-Feb-2020 00:43:01.419 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 10 22-Feb-2020 00:43:01.419 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 10.0 22-Feb-2020 00:43:01.419 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64 22-Feb-2020 00:43:01.419 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: C:\Program Files\Java\jdk1.8.0_241\jre 22-Feb-2020 00:43:01.419 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_241-b07 22-Feb-2020 00:43:01.419 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation 22-Feb-2020 00:43:01.419 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\Users\Геннадий\.IntelliJIdea2019.3\system\tomcat\Unnamed_ConcretePage_2 22-Feb-2020 00:43:01.420 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: C:\TomCat\apache-tomcat-9.0.30 22-Feb-2020 00:43:01.420 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\Геннадий\.IntelliJIdea2019.3\system\tomcat\Unnamed_ConcretePage_2\conf\logging.properties 22-Feb-2020 00:43:01.421 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 22-Feb-2020 00:43:01.421 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote= 22-Feb-2020 00:43:01.421 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099 22-Feb-2020 00:43:01.421 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false 22-Feb-2020 00:43:01.422 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.password.file=C:\Users\Геннадий\.IntelliJIdea2019.3\system\tomcat\Unnamed_ConcretePage_2\jmxremote.password 22-Feb-2020 00:43:01.422 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.access.file=C:\Users\Геннадий\.IntelliJIdea2019.3\system\tomcat\Unnamed_ConcretePage_2\jmxremote.access 22-Feb-2020 00:43:01.422 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1 22-Feb-2020 00:43:01.422 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048 22-Feb-2020 00:43:01.423 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources 22-Feb-2020 00:43:01.423 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs= 22-Feb-2020 00:43:01.423 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\Геннадий\.IntelliJIdea2019.3\system\tomcat\Unnamed_ConcretePage_2 22-Feb-2020 00:43:01.423 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\TomCat\apache-tomcat-9.0.30 22-Feb-2020 00:43:01.424 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\TomCat\apache-tomcat-9.0.30\temp 22-Feb-2020 00:43:01.424 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.23] using APR version [1.7.0]. 22-Feb-2020 00:43:01.424 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true]. 22-Feb-2020 00:43:01.424 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true] 22-Feb-2020 00:43:01.432 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1c 28 May 2019] 22-Feb-2020 00:43:01.878 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"] 22-Feb-2020 00:43:01.928 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"] 22-Feb-2020 00:43:01.934 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [840] milliseconds 22-Feb-2020 00:43:01.984 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina] 22-Feb-2020 00:43:01.985 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.30] 22-Feb-2020 00:43:02.003 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"] 22-Feb-2020 00:43:02.017 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"] 22-Feb-2020 00:43:02.022 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [86] milliseconds Connected to server [2020-02-22 12:43:02,357] Artifact ConcretePage:war exploded: Artifact is being deployed, please wait... 22-Feb-2020 00:43:06.552 INFO [RMI TCP Connection(3)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 22-Feb-2020 00:43:06.592 INFO [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.context.ContextLoader.initWebApplicationContext Root WebApplicationContext: initialization started 22-Feb-2020 00:43:07.807 WARNING [RMI TCP Connection(3)-127.0.0.1] org.springframework.context.support.AbstractApplicationContext.refresh Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webSecurityConfig': Unsatisfied dependency expressed through field 'dataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 22-Feb-2020 00:43:07.818 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.context.ContextLoader.initWebApplicationContext Context initialization failed org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webSecurityConfig': Unsatisfied dependency expressed through field 'dataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:401) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:292) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4683) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5146) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705) at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1728) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:289) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:456) at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:405) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:289) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) at com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468) at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) [2020-02-22 12:43:07,866] Artifact ConcretePage:war exploded: Error during artifact deployment. See server log for details. at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) at java.security.AccessController.doPrivileged(Native Method) at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1408) at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357) at sun.rmi.transport.Transport$1.run(Transport.java:200) at sun.rmi.transport.Transport$1.run(Transport.java:197) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:196) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1695) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1253) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ... 62 more 22-Feb-2020 00:43:07.828 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file 22-Feb-2020 00:43:07.834 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors 22-Feb-2020 00:43:12.010 INFO [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDirectory Установка веб приложения РІ папку [C:\TomCat\apache-tomcat-9.0.30\webapps\manager] 22-Feb-2020 00:43:12.209 INFO [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\TomCat\apache-tomcat-9.0.30\webapps\manager] has finished in [199] ms
下面是我的项目
包com. concretepage.config;
免费的Marker Config. class
package com.concretepage.config;import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver; @Configuration @ComponentScan({"com.concretepage"}) public class FreeMarkerConfig { @Bean public FreeMarkerConfigurer freeMarkerConfigurer() { FreeMarkerConfigurer configurer = new FreeMarkerConfigurer(); configurer.setTemplateLoaderPath("/WEB-INF/templates"); configurer.setDefaultEncoding("UTF-8"); return configurer; } @Bean public ViewResolver getViewResolver(){ FreeMarkerViewResolver viewResolver = new FreeMarkerViewResolver(); viewResolver.setSuffix(".ftl"); viewResolver.setContentType("text/html;charset=UTF-8"); viewResolver.setCache(false); return viewResolver; } }
消息Web应用程序初始化r. class
package com.concretepage.config;import com.concretepage.security.WebSecurityConfig; import org.springframework.core.annotation.Order; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; @Order(1) public class MessageWebApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override protected Class<?>[] getRootConfigClasses() { return new Class<?>[]{ WebSecurityConfig.class }; } @Override protected Class<?>[] getServletConfigClasses() { return new Class<?>[]{ SQLConfig.class, FreeMarkerConfig.class }; } @Override protected String[] getServletMappings() { return new String[] { "/" }; } }
SQL Config. class
package com.concretepage.config;import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.DriverManagerDataSource; import javax.sql.DataSource; @Configuration @ComponentScan("com.concretepage.security") public class SQLConfig { public SQLConfig() { } @Bean public DataSource dataSource() { DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource(); driverManagerDataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); driverManagerDataSource.setUrl("jdbc:mysql://localhost:3306/mysecurity?serverTimezone=UTC"); driverManagerDataSource.setUsername("root"); driverManagerDataSource.setPassword("1234"); return driverManagerDataSource; } }
包com. concretepage。安全;
安全Web应用程序初始化r. class
package com.concretepage.security;import org.springframework.core.annotation.Order; import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer; @Order(2) public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer { }
Web安全配置。类
package com.concretepage.security;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.configuration.*; import org.springframework.security.core.userdetails.User; import javax.sql.DataSource; @EnableWebSecurity public class WebSecurityConfig { @Autowired public DataSource dataSource; @Autowired public void configure(AuthenticationManagerBuilder auth) throws Exception { // ensure the passwords are encoded properly User.UserBuilder user = User.builder(); auth .jdbcAuthentication() .dataSource(dataSource) .withDefaultSchema() .withUser(user.username("user").password("{noop}password").roles("USER")) .withUser(user.username("admin").password("{noop}password").roles("USER","ADMIN")); } }
包com.concretepage;
家庭控制器. class
package com.concretepage;import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @Controller public class HomeController { @GetMapping("/") public String home () { return "/home"; } @GetMapping("/login") public String login () { return "/login"; } }
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.concretepage</groupId> <artifactId>ConcretePage</artifactId> <version>1.0-SNAPSHOT</version> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>${java.version}</source> <target>${java.version}</target> <encoding>${encoding}</encoding> </configuration> </plugin> </plugins> </build> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <failOnMissingWebXml>false</failOnMissingWebXml> <java.version>1.8</java.version> <encoding>UTF-8</encoding> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-framework-bom</artifactId> <version>5.2.3.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-bom</artifactId> <version>5.2.2.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <!-- Spring Security--> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-core</artifactId> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> </dependency> <!-- Spring Framework--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>4.0.1</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.19</version> </dependency> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>2.3.29</version> </dependency> </dependencies> </project>
显然您的WebSecurityConfig
在SQLConfig
中找不到bean。修改MessageWebApplicationStaralizer
;尝试将SQLConfig. class
放在getRootConfigClass()
中:
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[]{ WebSecurityConfig.class, SQLConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[]{FreeMarkerConfig.class };
}
// ...
getRootConfigClass()
中的所有配置类都用于创建父应用程序上下文,getServletConfigClass()
中的配置类是子上下文。子上下文可以@Autowire
root-context bean,但不能反过来。
在这篇SO文章中查看更多信息。