如何在Spring启动时配置HDIV

时间:2017-03-05 05:46:33

标签: java spring-mvc spring-boot hdiv

我想保护我的链接(安静的地址)。经过多次研究后,我发现HDIV framework并使用了它。 现在我想在Spring-boot中配置HDIV framework但它有一些错误!!我无法配置这个。谁可以帮助我?

我的POM.xml:

    <dependency>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-jasper</artifactId>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-el</artifactId>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jstl</artifactId>
            </dependency>
            <dependency>
                <groupId>org.company</groupId>
                <artifactId>framework-boot</artifactId>
                <version>1.0.0-releases</version>
                <type>jar</type>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.security</groupId>
                        <artifactId>spring-security-core</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.springframework.security</groupId>
                        <artifactId>spring-security-config</artifactId>
                    </exclusion>
                    <exclusion>
                                 <groupId>org.springframework.security</groupId>
                            <artifactId>spring-security-web</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.company</groupId>
                        <artifactId>font</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
            </dependency>
            <dependency>
                <groupId>org.company</groupId>
                <artifactId>framework-web-new</artifactId>
                <version>2.0.0-releases</version>
                <type>jar</type>
            </dependency>



            <!-- <HDIV></HDIV> -->


            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-core</artifactId>
                <version>4.1.1.RELEASE</version>
                <exclusions>
                    <exclusion>
                        <artifactId>spring-aop</artifactId>
                        <groupId>org.springframework</groupId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-config</artifactId>
                <version>4.1.1.RELEASE</version>
                <exclusions>
                    <exclusion>
                        <artifactId>spring-aop</artifactId>
                        <groupId>org.springframework</groupId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-web</artifactId>
                <version>4.1.1.RELEASE</version>
                <exclusions>
                    <exclusion>
                        <artifactId>spring-aop</artifactId>
                        <groupId>org.springframework</groupId>
                    </exclusion>
                </exclusions>
            </dependency>



            <dependency>
                <groupId>org.hdiv</groupId>
                <artifactId>spring-boot-starter-hdiv</artifactId>
                <version>1.0.0</version>
            </dependency>

            <dependency>
                <groupId>org.hdiv</groupId>
                <artifactId>hdiv-config</artifactId>
                <version>3.2.0</version>
            </dependency>
            <dependency>
                <groupId>org.hdiv</groupId>
                <artifactId>hdiv-spring-mvc</artifactId>
                <version>3.2.0</version>
            </dependency>
            <dependency>
                <groupId>org.hdiv</groupId>
                <artifactId>hdiv-core</artifactId>
                <version>3.2.0</version>
            </dependency>

我的配置类是:

@Configuration
@EnableHdivWebSecurity

public class MyHdivConfig extends HdivWebSecurityConfigurerAdapter {


@Override
public void configure(SecurityConfigBuilder builder) {

    builder.maxPagesPerSession(1)
    .randomName(true)
    .showErrorPageOnEditableValidation(true)
    .stateParameterName("mohsen")
    .validateUrlsWithoutParams(true)


    .sessionExpired()
            .homePage("/").loginPage("/Login.jsp")


            .and()
            .reuseExistingPageInAjaxRequest(true)
            ;
}


//  First Page
    @Override
    public void addExclusions(ExclusionRegistry registry) {

    registry.addUrlExclusions("/Login.jsp").method("GET");
}



//EditableValidation
@Override
public void addRules(RuleRegistry registry) {

    registry.addRule("customValidation").acceptedPattern("^[a-zA-Z0-9@.\\-_]*$");
}

@Override
public void configureEditableValidation(ValidationConfigurer validationConfigurer) {

    validationConfigurer.addValidation(".*").rules("customValidation");
}

但我有很多错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hdivConfig' defined in class path resource [org/hdiv/config/annotation/DelegatingHdivWebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.hdiv.config.HDIVConfig]: Factory method 'hdivConfig' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'editableDataValidationProvider' defined in class path resource [org/hdiv/config/annotation/DelegatingHdivWebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.hdiv.validator.EditableDataValidationProvider]: Factory method 'editableDataValidationProvider' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'editableValidationRepository' defined in class path resource [org/hdiv/config/annotation/DelegatingHdivWebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.hdiv.validator.ValidationRepository]: Factory method 'editableValidationRepository' threw exception; nested exception is java.lang.NoSuchMethodError: org.hdiv.config.annotation.ValidationConfigurer.addValidation(Ljava/lang/String;)Lorg/hdiv/config/annotation/ValidationConfigurer$ValidationConfig$RuleConfigurer;
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1128)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1023)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:751)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
at org.baharan.Application.main(Application.java:48)
aused by: java.lang.NoSuchMethodError: org.hdiv.config.annotation.ValidationConfigurer.addValidation(Ljava/lang/String;)Lorg/hdiv/config/annotation/ValidationConfigurer$ValidationConfig$RuleConfigurer;
at org.hdiv.spring.boot.autoconfigure.HdivAutoConfiguration$HdivDefaultConfiguration.configureEditableValidation(HdivAutoConfiguration.java:93)
at org.hdiv.config.annotation.configuration.HdivWebSecurityConfigurerComposite.configureEditableValidation(HdivWebSecurityConfigurerComposite.java:66)
at org.hdiv.config.annotation.DelegatingHdivWebSecurityConfiguration.configureEditableValidation(DelegatingHdivWebSecurityConfiguration.java:82)
at org.hdiv.config.annotation.AbstractHdivWebSecurityConfiguration.getValidationsData(AbstractHdivWebSecurityConfiguration.java:416)
at org.hdiv.config.annotation.AbstractHdivWebSecurityConfiguration.editableValidationRepository(AbstractHdivWebSecurityConfiguration.java:369)
at org.hdiv.config.annotation.DelegatingHdivWebSecurityConfiguration$$EnhancerBySpringCGLIB$$61ea94d.CGLIB$editableValidationRepository$34(<generated>)
at org.hdiv.config.annotation.DelegatingHdivWebSecurityConfiguration$$EnhancerBySpringCGLIB$$61ea94d$$FastClassBySpringCGLIB$$3c036c14.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)
at org.hdiv.config.annotation.DelegatingHdivWebSecurityConfiguration$$EnhancerBySpringCGLIB$$61ea94d.editableValidationRepository(<generated>)
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:497)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 63 common frames omitted

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

查看Hdiv示例应用程序:https://github.com/hdiv/spring-boot-sample-hdiv/blob/master/pom.xml

将Hdiv Starter更新到上一版本1.1.0并删除不必要的依赖项。