Tag: spring boot

org.postgresql.util.PSQLException:错误:关系“app_user”不存在

我有一个应用程序,我正在使用spring boot和postgres。 我尝试创建用户时收到此错误。 当我在我的数据库上运行此查询时,我得到相同的错误: select * from APP_USER ERROR: relation “app_user” does not exist LINE 1: select * from APP_USER ^ ********** Error ********** ERROR: relation “app_user” does not exist SQL state: 42P01 但如果我改为: select * from “APP_USER” 有用。 如何在我的春季启动应用程序上配置它? pom.xml中的依赖项: org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-actuator org.springframework.boot spring-boot-starter-data-jpa org.springframework.boot spring-boot-starter-security org.springframework.boot spring-boot-starter-thymeleaf org.thymeleaf.extras thymeleaf-extras-tiles2 2.1.1.RELEASE org.postgresql […]

Spring Security通过并发登录尝试来锁定用户

我是安全新手,遇到了导致用户帐户被锁定的问题,只有应用程序重新启动才能修复它。 我有一个弹簧启动(1.3.0.BUILD-SNAPSHOT)与弹簧安全(4.0.2.RELEASE)应用程序,我试图控制并发会话策略,以便用户只能有一个登录。 它正确检测来自其他浏览器的后续登录尝试并阻止它。 但是,我注意到一些我似乎无法追查的奇怪行为: 用户可以在同一浏览器中对两个选项卡进行身份validation。 我无法使用三个标签登录,但有两个标签。 退出一个似乎注销两者。 我看到cookie的值是一样的,所以我猜他们正在共享一个会话: 表1 JSESSIONID: DA7C3EF29D55297183AF5A9BEBEF191F &941135CEBFA92C3912ADDC1DE41CFE9A 表2 JSESSIONID: DA7C3EF29D55297183AF5A9BEBEF191F &48C17A19B2560EAB8EC3FDF51B179AAE 第二次登录尝试会显示以下日志消息,这些消息似乎表示第二次登录尝试(我通过Spring-Security源步进来validation: osswaiFilterSecurityInterceptor : Secure object: FilterInvocation: URL: /loginPage; Attributes: [permitAll] osswaiFilterSecurityInterceptor : Previously Authenticated: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@754041c8: Principal: User [username=xxx@xxx.xx, password= ]; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@43458: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 4708D404F64EE758662B2B308F36FFAC; Granted Authorities: Owner ossaccess.vote.AffirmativeBased : Voter: org.springframework.security.web.access.expression.WebExpressionVoter@17527bbe, returned: 1 […]

在Spring Boot测试类上使用@WebMvcTest批注时出错

我已经按照这里描述的“测试Spring MVC切片”​​部分为Spring MVC控制器编写了一个测试类。 这个类看起来像这样: @RunWith(SpringRunner.class) @WebMvcTest(controllers=OurController.class) public class OurControllerTest { @Autowired private MockMvc mvc; @MockBean private OurRepository ourRepository; @Test public void testGetStuff() { // code removed } } 当我运行它时,我收到以下错误: MockHttpServletResponse: Status = 401 Error message = null Headers = {Cache-Control=[no-store], Pragma=[no-cache], WWW-Authenticate=[Bearer realm=”oauth2-resource”, error=”unauthorized”, error_description=”Full authentication is required to access this resource”], Content-Type=[application/json;charset=UTF-8], X-Content-Type-Options=[nosniff], X-XSS-Protection=[1; […]

Netflix Feign – 通过微服务传播状态和exception

我正在使用Netflix Feign将微服务A的一个操作调用到微服务B的其他操作,该操作使用Spring Bootvalidation代码。 如果validation不好,微服务B的操作会抛出exception。 然后我在微服务中处理并返回一个HttpStatus.UNPROCESSABLE_ENTITY (422),如下所示: @ExceptionHandler({ ValidateException.class }) @ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY) @ResponseBody public Object validationException(final HttpServletRequest request, final validateException exception) { log.error(exception.getMessage(), exception); error.setErrorMessage(exception.getMessage()); error.setErrorCode(exception.getCode().toString()); return error; } 因此,当微服务A在接口中调用B作为下一个: @Headers(“Content-Type: ” + MediaType.APPLICATION_JSON_UTF8_VALUE) @RequestLine(“GET /other”) void otherOperation(@Param(“other”) String other ); @Headers(“Content-Type: ” + MediaType.APPLICATION_JSON_UTF8_VALUE) @RequestLine(“GET /code/validate”) Boolean validate(@Param(“prefix”) String prefix); static PromotionClient connect() { return Feign.builder() […]

Spring启动外部application.properties

我正在开发一个spring boot应用程序 我想用外部文件覆盖src/main/resources/application.properties一些属性(例如/etc/projectName/application.properties )。 我尝试了几种方法: @PropertySource(“file:/etc/projectName/application.properties”)作为ApplicationConfig.java注释 我的application.properties resources spring.config.location=/etc/projectName/application.properties 我用spring.port测试了它。 第一种方法只添加了属性,但没有覆盖它们。

由于缺少bean,Webserver无法启动

我正在尝试启动一个简单的spring应用程序 我在这里有main.java文件: package main; import javafx.application.Application; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.ComponentScan; @ComponentScan @EnableAutoConfiguration public class Main { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } 这是我的libs: 这是pom.xml: 4.0.0 blog blog 1.0-SNAPSHOT org.springframework spring-web 4.0.0.RELEASE org.springframework.boot spring-boot-autoconfigure 1.0.0.BUILD-SNAPSHOT org.springframework.boot spring-boot 1.0.0.BUILD-SNAPSHOT 最后错误就是这个: . ____ _ __ _ _ /\\ / ___’_ __ _ […]

Spring Boot ConflictingBeanDefinitionException:@Controller类的注释指定bean名称

我一直在Spring启动应用程序中收到ConflictingBeanDefinitionException错误。 我不完全确定如何解决它,我有几个@Configuration注释类帮助建立Thymeleaf,Spring Security和Web。 为什么应用程序试图设置homeController两次? (它在哪里尝试这样做?) 错误是: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [org.kemri.wellcome.hie.Application]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name ‘homeController’ for bean class [org.kemri.wellcome.hie.HomeController] conflicts with existing, non-compatible bean definition of same name and class [org.kemri.wellcome.hie.controller.HomeController] 我的spring boot主应用程序初始化程序: @EnableScheduling @EnableAspectJAutoProxy @EnableCaching @Configuration @ComponentScan @EnableAutoConfiguration public class Application extends SpringBootServletInitializer { public static void main(String[] […]

如何在弹簧靴中设置过滤链?

我遇到了spring-boot,并打算为传入请求添加一个filter链。 这是应用程序: package example.hello; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; @SpringBootApplication public class Application { public static void main(String[] args) { ApplicationContext ctx = SpringApplication.run(Application.class, args); } } 这是控制器: package example.hello; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.concurrent.atomic.AtomicLong; @RestController public class GreetingController { private static final String template = “Hello, %s!”; private final AtomicLong […]

Spring Boot OAuth2在1.4.1版上无法正常运行

我在Spring OAuth2上使用Spring Boot 1.4.0。 当我请求令牌时,服务器响应是: { “access_token”: “93f8693a-22d2-4139-a4ea-d787f2630f04”, “token_type”: “bearer”, “refresh_token”: “2800ea24-bb4a-4a01-ba87-2d114c1a2235”, “expires_in”: 899, “scope”: “read write” } 当我将项目更新到Spring Boot 1.4.1时,服务器响应变为 { “error”: “invalid_client”, “error_description”: “Bad client credentials” } 什么从版本1.4.0更改为1.4.1? 我应该怎样做才能让我的请求再次发挥作用? 编辑 WebSecurityConfiguration: @Configuration @EnableWebSecurity public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter{ /** The client details service. */ @Autowired private ClientDetailsService clientDetailsService; /** The password encoder. */ […]

将Gradle.build版本导入Spring Boot

我正在尝试在视图中显示我的Spring Boot应用程序的应用程序版本。 我确定我可以访问这个版本信息,我只是不知道如何。 我尝试了以下信息: https : //docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html ,并将其放在我的application.properties : info.build.version=${version} 然后在我的控制器中加载@Value(“${version.test}”) ,但这不起作用,我只会得到如下错误: Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder ‘version’ in string value “${version}” 有关获取我的应用程序版本,弹簧启动版本等信息的正确方法的任何建议到我的控制器?