小编And*_*son的帖子

Spring启动csrf过滤器

我试图为某些特定的api调用启用csrf过滤器,而其他人则不需要csrf过滤器.我所做的是

@Override

protected void configure(HttpSecurity http) throws Exception {

    http.csrf().disable().authorizeRequests().antMatchers("/public/**").permitAll();
    http.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint);
    http.csrf().disable().addFilterBefore(new StatelessCSRFFilter(), CsrfFilter.class).authorizeRequests().antMatchers("/rest/**").permitAll();
}
Run Code Online (Sandbox Code Playgroud)

问题是当我调用localhost:8080/public/hello时

出现错误

"message":"缺少或不匹配的CSRF令牌"

我正在使用Spring启动和Spring Security.

谢谢你的帮助.

java spring spring-mvc spring-security spring-boot

3
推荐指数
1
解决办法
6116
查看次数

如何在Gradle中使用Spring IO Platform BOM和Spring Boot?

所以这build.gradle似乎工作正常

buildscript {
    repositories {
        mavenLocal()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath('org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE')
    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'


jar {
    baseName = 'entity-api'
    version = '0.1.0-SNAPSHOT'
}

repositories {
    mavenLocal()
    jcenter()
    mavenCentral()
}

dependencies {
    compile('org.springframework.data:spring-data-commons')
    testCompile('junit:junit')
    testCompile('org.mockito:mockito-core')
    testCompile('nl.jqno.equalsverifier:equalsverifier:1.7.5')
}
Run Code Online (Sandbox Code Playgroud)

我试着加入什么记录这样

buildscript {
    repositories {
        mavenLocal()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath('org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE')
        classpath( 'io.spring.gradle:dependency-management-plugin:0.5.1.RELEASE')
    }
}

apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'


jar {
    baseName …
Run Code Online (Sandbox Code Playgroud)

gradle build.gradle spring-boot spring-io

3
推荐指数
1
解决办法
1075
查看次数

堆栈在EC2实例上不存在错误,但在本地工作正常

我低于异常,也没有任何解决方案来解决问题。另外,如果您想知道的话,我在gradle文件中使用了Amazon Cloud sqs依赖项。任何帮助将不胜感激。

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stackResourceRegistryFactoryBean' defined in class path resource [org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration$StackAutoDetectConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.env.stack.config.StackResourceRegistryFactoryBean]: Factory method 'stackResourceRegistryFactoryBean' threw exception; nested exception is com.amazonaws.AmazonServiceException: Stack for i-123d410f does not exist (Service: AmazonCloudFormation; Status Code: 400; Error Code: ValidationError; Request ID: cc12e6b5-805e-11e5-9847-a3f73a9dcc2f)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044) …
Run Code Online (Sandbox Code Playgroud)

java amazon-ec2 amazon-sqs spring-boot spring-cloud

3
推荐指数
1
解决办法
1377
查看次数

从Spring Boot 1.3升级到1.4 RC1时,org.hibernate.internal.SessionFactoryImpl.<init>抛出的AbstractMethodError

我有一个非常简单的Spring Boot 1.3应用程序,我正在尝试升级到1.4 RC1.没有什么不是开箱即用的配置.当我尝试启动应用程序或运行测试时,我得到以下内容:

12:06:27.237 [QUIET] [system.out] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError
12:06:27.237 [QUIET] [system.out]   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
12:06:27.237 [QUIET] [system.out]   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
12:06:27.237 [QUIET] [system.out]   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
12:06:27.237 [QUIET] [system.out]   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
12:06:27.237 [QUIET] [system.out]   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
12:06:27.238 [QUIET] [system.out]   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
12:06:27.238 [QUIET] [system.out]   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
12:06:27.238 [QUIET] [system.out]   at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076) ~[spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
12:06:27.238 [QUIET] [system.out] …
Run Code Online (Sandbox Code Playgroud)

java spring gradle spring-boot

3
推荐指数
1
解决办法
3706
查看次数

SpringBoot执行器system.cpu.count指标和system.cpu.usage指标之间的关系

只是想从 SpringBoot 2.3.1 执行器指标端点获得有关 system.cpu.count 指标和 system.cpu.usage 指标之间关系的一些说明。

例如,就我而言:

/actuator/metrics/system.cpu.count 的值为:2

/actuator/metrics/system.cpu.usage 的值为:0.024765603908878

这是否意味着我的CPU利用率是:0.024765603908878 / 2 * 100 = 1.24% ?

spring-boot spring-boot-actuator micrometer

2
推荐指数
1
解决办法
4730
查看次数

为什么spring-boot应用程序中pom.xml的第一行显示错误... &lt;?xml version =“ 1.0” encoding =“ UTF-8”?&gt;

<?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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
    </parent>
    <groupId>com.app</groupId>
    <artifactId>Demo</artifactId>
    <version>1.0</version>
    <name>Demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
Run Code Online (Sandbox Code Playgroud)

spring-boot

1
推荐指数
2
解决办法
3324
查看次数

原因:未能确定合适的驱动类:spring boot 使用eclipse

我在控制台中收到以下错误:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2020-10-09 19:17:13.032  INFO 2692 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-10-09 19:17:13.065  INFO 2692 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-10-09 19:17:13.073 ERROR 2692 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description: …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate maven spring-boot

1
推荐指数
1
解决办法
1万
查看次数

如何启动两个春季启动应用程序

我正在玩春季靴子.所以我想创建两个互相交互的微服务.我的问题是我无法启动它们,因为当第一个应用程序已经使用自己的tomcat运行时,第二个应用程序无法启动:

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
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

谢谢!

spring tomcat spring-boot

0
推荐指数
2
解决办法
1393
查看次数