Java Config中没有id或名称的Spring Bean

时间:2014-04-16 13:55:03

标签: spring saml-2.0

如何正确地将没有ID的Spring bean从XML转换为JAVA Config?

<bean class="org.springframework.security.saml.SAMLBootstrap"/>

注意:

写作:

@Bean
public SAMLBootstrap samlBootstrap() {
    return new SAMLBootstrap();
}

Spring boot在运行时返回错误。

2014-04-16 16:15:53.580  INFO 3372 --- [           main] it.prisma.toys.sso.Application           : Starting Application on SAN10462 with PID 3372 (started by v.denotaris)
2014-04-16 16:15:53.722  INFO 3372 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@67622d29: startup date [Wed Apr 16 16:15:53 CEST 2014]; root of context hierarchy
2014-04-16 16:15:57.523  WARN 3372 --- [           main] o.s.c.a.ConfigurationClassEnhancer       : @Bean method WebSecurityConfig.samlBootstrap is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean Javadoc for complete details
2014-04-16 16:16:03.308  INFO 3372 --- [           main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 8080
2014-04-16 16:16:03.957  INFO 3372 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2014-04-16 16:16:03.958  INFO 3372 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/7.0.52
2014-04-16 16:16:04.340  INFO 3372 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2014-04-16 16:16:04.341  INFO 3372 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 10628 ms
2014-04-16 16:16:04.777 ERROR 3372 --- [cat-startStop-1] org.apache.catalina.core.ContainerBase   : A child container failed during start

java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:188)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:799)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    ... 6 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.servlet.Filter org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain() throws java.lang.Exception] threw exception; nested exception is java.lang.IllegalStateException: org.springframework.security.config.annotation.ObjectPostProcessor is a required bean. Ensure you have used @EnableWebSecurity and @Configuration
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:597)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getOrderedBeansOfType(EmbeddedWebApplicationContext.java:367)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getServletContextInitializerBeans(EmbeddedWebApplicationContext.java:268)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext$1.onStartup(EmbeddedWebApplicationContext.java:213)
    at org.springframework.boot.context.embedded.tomcat.ServletContextInitializerLifecycleListener.lifecycleEvent(ServletContextInitializerLifecycleListener.java:54)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5355)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 6 common frames omitted
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.servlet.Filter org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain() throws java.lang.Exception] threw exception; nested exception is java.lang.IllegalStateException: org.springframework.security.config.annotation.ObjectPostProcessor is a required bean. Ensure you have used @EnableWebSecurity and @Configuration
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:188)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586)
    ... 22 common frames omitted
Caused by: java.lang.IllegalStateException: org.springframework.security.config.annotation.ObjectPostProcessor is a required bean. Ensure you have used @EnableWebSecurity and @Configuration
    at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter$1.postProcess(WebSecurityConfigurerAdapter.java:71)
    at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.getHttp(WebSecurityConfigurerAdapter.java:168)
    at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:276)
    at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:61)
    at it.prisma.toys.sso.config.WebSecurityConfig$$EnhancerBySpringCGLIB$$5855fc5.init(<generated>)
    at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.init(AbstractConfiguredSecurityBuilder.java:369)
    at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.doBuild(AbstractConfiguredSecurityBuilder.java:322)
    at org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:39)
    at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain(WebSecurityConfiguration.java:92)
    at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$1e4d7c3c.CGLIB$springSecurityFilterChain$3(<generated>)
    at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$1e4d7c3c$$FastClassBySpringCGLIB$$edee68cb.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)
    at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$1e4d7c3c.springSecurityFilterChain(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
    ... 23 common frames omitted

2014-04-16 16:16:04.792 ERROR 3372 --- [           main] org.apache.catalina.core.ContainerBase   : A child container failed during start

java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost]]
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:188)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:731)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.startup.Tomcat.start(Tomcat.java:341)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:79)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:69)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:270)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:145)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:159)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:132)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:120)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:648)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:311)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:909)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:898)
    at it.prisma.toys.sso.Application.main(Application.java:14)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:799)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 6 common frames omitted

2014-04-16 16:16:04.796  INFO 3372 --- [           main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/C:/Users/v.denotaris/Documents/Spring%20Tool%20Suite%20Environment/Workspace/TOY_MIUR_PRISMA-2.1-SSO/target/classes/, file:/C:/Users/v.denotaris/.m2/repository/org/springframework/boot/spring-boot-starter-web/1.0.1.RELEASE/spring-boot-starter-web-1.0.1.RELEASE.jar, file:/C:/Users/v.denotaris/.m2/repository/org/springframework/boot/spring-boot-starter/1.0.1.RELEASE/spring-boot-starter-1.0.1.RELEASE.jar, file:/C:/Users/v.denotaris/.m2/repository/org/springframework/boot/spring-boot/1.0.1.RELEASE/spring-boot-1.0.1.RELEASE.jar, file:/C:/Users/v.denotaris/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.0.1.RELEASE/spring-boot-autoconfigure-1.0.1.RELEASE.jar, file:/C:/Users/v.denotaris/.m2/repository/org/springframework/boot/spring-boot-starter-logging/1.0.1.RELEASE/spring-boot-starter-logging-1.0.1.RELEASE.jar, file:/C:/Users/v.denotaris/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.6/jcl-over-slf4j-1.7.6.jar, file:/C:/Users/v.denotaris/.m2/repository/org/slf4j/jul-to-slf4j/1.7.6/jul-to-slf4j-1.7.6.jar, file:/C:/Users/v.denotaris/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.6/log4j-over-slf4j-1.7.6.jar, file:/C:/Users/v.denotaris/.m2/repository/ch/qos/logback/logback-classic/1.1.2/logback-classic-1.1.2.jar, file:/C:/Users/v.denotaris/.m2/repository/ch/qos/logback/logback-core/1.1.2/logback-core-1.1.2.jar, file:/C:/Users/v.denotaris/.m2/repository/org/yaml/snakeyaml/1.13/snakeyaml-1.13.jar, file:/C:/Users/v.denotaris/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/1.0.1.RELEASE/spring-boot-starter-tomcat-1.0.1.RELEASE.jar, file:/C:/Users/v.denotaris/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/7.0.52/tomcat-embed-core-7.0.52.jar, file:/C:/Users/v.denotaris/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/7.0.52/tomcat-embed-el-7.0.52.jar, file:/C:/Users/v.denotaris/.m2/repository/org/apache/tomcat/embed/tomcat-embed-logging-juli/7.0.52/tomcat-embed-logging-juli-7.0.52.jar, file:/C:/Users/v.denotaris/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.3.2/jackson-databind-2.3.2.jar, file:/C:/Users/v.denotaris/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.3.0/jackson-annotations-2.3.0.jar, file:/C:/Users/v.denotaris/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.3.2/jackson-core-2.3.2.jar, file:/C:/Users/v.denotaris/.m2/repository/org/springframework/spring-web/4.0.3.RELEASE/spring-web-4.0.3.RELEASE.jar, file:/C:/Users/v.denotaris/.m2/repository/org/springframework/spring-webmvc/4.0.3.RELEASE/spring-webmvc-4.0.3.RELEASE.jar, file:/C:/Users/v.denotaris/.m2/repository/org/springframework/boot/spring-boot-starter-security/1.0.1.RELEASE/spring-boot-starter-security-1.0.1.RELEASE.jar, file:/C:/Users/v.denotaris/.m2/repository/org/springframework/security/spring-security-config/3.2.3.RELEASE/spring-security-config-3.2.3.RELEASE.jar, file:/C:/Users/v.denotaris/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar, file:/C:/Users/v.denotaris/.m2/repository/org/springframework/security/spring-security-web/3.2.3.RELEASE/spring-security-web-3.2.3.RELEASE.jar, file:/C:/Users/v.denotaris/.m2/repository/org/springframework/spring-aop/4.0.3.RELEASE/spring-aop-4.0.3.RELEASE.jar, file:/C:/Users/v.denotaris/.m2/repository/org/springframework/spring-beans/4.0.3.RELEASE/spring-beans-4.0.3.RELEASE.jar, file:/C:/Users/v.denotaris/.m2/repository/org/springframework/spring-context/4.0.3.RELEASE/spring-context-4.0.3.RELEASE.jar, file:/C:/Users/v.denotaris/.m2/repository/org/springframework/spring-core/4.0.3.RELEASE/spring-core-4.0.3.RELEASE.jar, file:/C:/Users/v.denotaris/.m2/repository/org/springframework/spring-expression/4.0.3.RELEASE/spring-expression-4.0.3.RELEASE.jar, file:/C:/Users/v.denotaris/.m2/repository/org/springframework/boot/spring-boot-starter-thymeleaf/1.0.1.RELEASE/spring-boot-starter-thymeleaf-1.0.1.RELEASE.jar, file:/C:/Users/v.denotaris/.m2/repository/org/thymeleaf/thymeleaf-spring4/2.1.2.RELEASE/thymeleaf-spring4-2.1.2.RELEASE.jar, file:/C:/Users/v.denotaris/.m2/repository/org/thymeleaf/thymeleaf/2.1.2.RELEASE/thymeleaf-2.1.2.RELEASE.jar, file:/C:/Users/v.denotaris/.m2/repository/ognl/ognl/3.0.6/ognl-3.0.6.jar, file:/C:/Users/v.denotaris/.m2/repository/org/javassist/javassist/3.18.1-GA/javassist-3.18.1-GA.jar, file:/C:/Users/v.denotaris/.m2/repository/nz/net/ultraq/thymeleaf/thymeleaf-layout-dialect/1.2.2/thymeleaf-layout-dialect-1.2.2.jar, file:/C:/Users/v.denotaris/.m2/repository/org/springframework/security/extensions/spring-security-saml2-core/1.0.0.RC3-SNAPSHOT/spring-security-saml2-core-1.0.0.RC3-SNAPSHOT.jar, file:/C:/Users/v.denotaris/.m2/repository/org/opensaml/opensaml/2.5.3/opensaml-2.5.3.jar, file:/C:/Users/v.denotaris/.m2/repository/org/opensaml/openws/1.4.4/openws-1.4.4.jar, file:/C:/Users/v.denotaris/.m2/repository/org/opensaml/xmltooling/1.3.4/xmltooling-1.3.4.jar, file:/C:/Users/v.denotaris/.m2/repository/org/bouncycastle/bcprov-jdk15/1.46/bcprov-jdk15-1.46.jar, file:/C:/Users/v.denotaris/.m2/repository/ca/juliusdavies/not-yet-commons-ssl/0.3.9/not-yet-commons-ssl-0.3.9.jar, file:/C:/Users/v.denotaris/.m2/repository/org/apache/santuario/xmlsec/1.4.5/xmlsec-1.4.5.jar, file:/C:/Users/v.denotaris/.m2/repository/commons-logging/commons-logging/1.1/commons-logging-1.1.jar, file:/C:/Users/v.denotaris/.m2/repository/log4j/log4j/1.2.17/log4j-1.2.17.jar, file:/C:/Users/v.denotaris/.m2/repository/logkit/logkit/1.0.1/logkit-1.0.1.jar, file:/C:/Users/v.denotaris/.m2/repository/avalon-framework/avalon-framework/4.1.3/avalon-framework-4.1.3.jar, file:/C:/Users/v.denotaris/.m2/repository/javax/servlet/servlet-api/2.3/servlet-api-2.3.jar, file:/C:/Users/v.denotaris/.m2/repository/commons-httpclient/commons-httpclient/3.1/commons-httpclient-3.1.jar, file:/C:/Users/v.denotaris/.m2/repository/commons-codec/commons-codec/1.3/commons-codec-1.3.jar, file:/C:/Users/v.denotaris/.m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar, file:/C:/Users/v.denotaris/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar, file:/C:/Users/v.denotaris/.m2/repository/velocity/velocity/1.5/velocity-1.5.jar, file:/C:/Users/v.denotaris/.m2/repository/org/owasp/esapi/esapi/2.0.1/esapi-2.0.1.jar, file:/C:/Users/v.denotaris/.m2/repository/joda-time/joda-time/2.3/joda-time-2.3.jar, file:/C:/Users/v.denotaris/.m2/repository/xml-apis/xml-apis/1.4.01/xml-apis-1.4.01.jar, file:/C:/Users/v.denotaris/.m2/repository/xerces/xercesImpl/2.10.0/xercesImpl-2.10.0.jar, file:/C:/Users/v.denotaris/.m2/repository/xml-resolver/xml-resolver/1.2/xml-resolver-1.2.jar, file:/C:/Users/v.denotaris/.m2/repository/xalan/xalan/2.7.1/xalan-2.7.1.jar, file:/C:/Users/v.denotaris/.m2/repository/xalan/serializer/2.7.1/serializer-2.7.1.jar, file:/C:/Users/v.denotaris/.m2/repository/org/slf4j/slf4j-api/1.7.6/slf4j-api-1.7.6.jar, file:/C:/Users/v.denotaris/.m2/repository/org/springframework/security/spring-security-core/3.2.3.RELEASE/spring-security-core-3.2.3.RELEASE.jar]
Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:135)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:120)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:648)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:311)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:909)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:898)
    at it.prisma.toys.sso.Application.main(Application.java:14)
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:106)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:69)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:270)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:145)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:159)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:132)
    ... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardServer[-1]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.startup.Tomcat.start(Tomcat.java:341)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:79)
    ... 12 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Tomcat]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:731)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 14 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 16 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 18 more

否则,通过对上面的xml使用@ImportResource,一切正常。

主要课程:

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

我的配置:

MvcConfig:

@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/home").setViewName("home");
        registry.addViewController("/").setViewName("home");
        registry.addViewController("/hello").setViewName("hello");
        registry.addViewController("/login").setViewName("login");
    }

}

这是我的整个安全配置类:

@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    // XML parser pool needed for OpenSAML parsing
    @Bean
    public StaticBasicParserPool parserPool() {
        StaticBasicParserPool parserPool = new StaticBasicParserPool();
        try {
            parserPool.initialize();
        } catch (XMLParserException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return parserPool;
    }

    @Bean
    public ParserPoolHolder parserPoolHolder() {
        return new ParserPoolHolder();
    }

    @Bean
    public SAMLBootstrap sAMLBootstrap() {
        return new SAMLBootstrap();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/", "/home").permitAll()
                .anyRequest().authenticated();
        http
            .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
            .logout()
                .permitAll();
    }
}

2 个答案:

答案 0 :(得分:0)

我遇到了同样的问题并通过在SAMLBootstrap文件中包含Application.java bean而不是WebSecurityConfig.java来管理它。

主要课程:

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {

    @Bean
    SAMLBootstrap samlBootstrap() {
        return new SAMLBootstrap();
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

答案 1 :(得分:0)

我认为相当于没有idname属性的bean的基于XML的定义是使用@Component注释。

以下是问题中给出的示例bean。

<bean class="org.springframework.security.saml.SAMLBootstrap"/>

可以通过在类中添加@Component注释来在Java中定义等效bean。

package org.springframework.security.saml;

@Component
public class SAMLBootstrap {
    ...
}

请参阅标题为&#34; Enabling component scanning with scan(String…​)&#34;的部分。在Spring Framework文档中获取更多信息。

  

在上面的示例中,将扫描com.acme包,查找任何@Component - 带注释的类,这些类将在容器中注册为Spring bean定义。