Tag: spring boot

@AuthenticationPrincipal与Spring Boot无法正常工作

使用Spring Boot 1.3.1,我遇到了@AuthenticationPrincipal问题。 这是我的控制器: @RestController @RequestMapping(“/api/user”) public class UserController { @RequestMapping(“/”) public UserDto user(@AuthenticationPrincipal(errorOnInvalidType = true) User user) { return UserDto.fromUser(user); } } 这是我自定义的User类: @Entity() @Table(name = “app_user”) public class User extends AbstractEntity implements Serializable { // —————————— FIELDS —————————— @NotNull @Column(unique = true) @Pattern(regexp = “[a-zA-Z_\\-\\.0-9]+”) @Size(min = 1, max = 20) private String […]

如何使用Spring-Boot和OAuth2限制特定域登录

我已经使用spring boot和Google成功完成了OAuth2登录,但我想限制登录到特定域(我们正在使用Google Apps for Work)。 我认为我应该通过扩展类OAuth2ClientAuthenticationProcessingFilter( 在此线程中指定)来处理,但我不知道如何做到这一点。 基本上,我想使用Google OAuth 2.0作为身份提供商,但只能接受公司用户(@ company.com)。

Spring Field需要一个无法找到的类型的bean Spring JPA

这是我在论坛上的第一个问题,因为我几乎陷入了死胡同。 我使用spring开发一个宁静的Web服务,在该服务中我想使用spring数据在db中存储一些数据。 但是,按照网站上的教程和我的入门指南,我不断遇到类似的问题,似乎这些教程总是缺少一些东西。 这是我的代码。 Application.java package hello; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.context.annotation.ComponentScan; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; @SpringBootApplication(scanBasePackages=”hello.Application”) @EnableJpaRepositories(“hello.provScoreRepo”) @ComponentScan(“Controller”) @EntityScan(“hello.provScore”) public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } provScore.java package hello; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @Entity public class provScore { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long […]

无法从salesforce站点重定向回Spring Boot JSP

我正在开发Spring Boot + Apache Oltu + Salesforce Integration示例。 在这个例子中,我试图调用Salesforce URL,但它应该通过Controller进行,但不会被调用。 问题是什么? 在后端,以下是执行,但不知道为什么它不重定向? 有什么快速帮助? @RequestMapping(value = “/redirect”, method = RequestMethod.GET) public HttpEntity redirect( @RequestParam(value = “code”, required = false) String code) throws OAuthSystemException, OAuthProblemException { String value = “UNKNOWN”; if (code != null && code.length() > 0) { System.out.println(“Received CODE: “+code); String details = getAccessToken(code); value […]

如何在Spring中的RESTful Web应用程序中进行身份validation(登录/注销)?

我想通过身份validation http://myhost/login?user=…&password=… 并注销 http://myhost/logout 我正在使用Gradle,Spring Boot和Java配置,因此没有web.xml,没有上下文配置,没有Web表单等等。 在多页和多文件样本上无法摆脱谷歌噪音……

使用@Configuration和@Controller注释一个类。 需要帮助重构

下面是我必须同时使用@Configuration和@Controller类,因为在整个应用程序中应该只有一个Thymeleaf实例,否则我会得到例外。 我的其他类用@RequestScope注释,所以我不能使用单例作用域bean。 所以我有一个配置和控制器的混合来获得结果,但我觉得这是一个不好的做法。 我将不胜感激任何帮助重构代码并删除不良做法。 UPDATE 我使用的是spring-boot 1.5.14 。 我使用以下方法处理模板并将处理后的模板保持为字符串。 @Controller @Configuration @EnableWebMvc @ApplicationScope public class MyThymeleafConfig { @GetMapping(“/view-template”) @ResponseBody public void viewTemplates() { Context context = new Context(); context.setVariable(“mydata”, “this is it”); String html = templateEngine().process(“templates/view-to-process.html”, context); System.out.println(html); } /* configuration for thymeleaf and template processing */ @Bean public SpringTemplateEngine templateEngine() { SpringTemplateEngine templateEngine = […]

Spring boot:找不到javassist

我从弹簧启动开始,我正在尝试在内存DB中编写一个小型应用程序和H2。 当我试图运行我的应用程序时,我有java.lang.ClassNotFoundException:javassist.bytecode.ClassFile所以我猜测类路径上缺少javassit jar。 我在调试模式下启动了应用程序,并且类路径中存在javassist-3.18.1-GA.jar。 我当然错过了一些东西,但我无法弄清楚是什么。 这是我的POM文件的内容 org.springframework.boot spring-boot-starter-parent 1.3.1.BUILD-SNAPSHOT org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-devtools true org.springframework.boot spring-boot-starter-data-jpa com.h2database h2 org.springframework.boot spring-boot-maven-plugin 1.8 spring-snapshots http://repo.spring.io/snapshot true spring-milestones http://repo.spring.io/milestone spring-snapshots http://repo.spring.io/snapshot spring-milestones http://repo.spring.io/milestone 这是我的应用程序主类 @Configuration @EnableAutoConfiguration @ComponentScan public class Application { public static void main(String[] args) throws Exception{ SpringApplication.run(Application.class, args); } } 这是堆栈跟踪 org.springframework.beans.factory.BeanCreationException: Error creating bean with […]

Java Spring:POST Request在传递JSON对象时输出意外的415错误

我正在创建一个接收以下输入的API,并提供以下输出。 所以我需要有一个猜测function。 到目前为止,我还没有运气测试我的代码。 当我发送POST(使用POSTMan)到http:// localhost:8080 / guess时身体为{“game”:”klubxb”, “guess”:”a”} 。 我将Content-type设置为application/json ,并且正文为{“game”:”lmzxmn”,”guess”:”c”} 这是回应: { “timestamp”: “2018-04-28T00:40:29.141+0000”, “status”: 500, “error”: “Internal Server Error”, “message”: “No message available”, “path”: “/guess” } 我为猜测定义的函数是: @RequestMapping(value = “/guess”, method = RequestMethod.POST, consumes = “application/json”, produces = “application/json”) public Game makeGuess(@RequestBody Guess gameAndLetter, HttpSession session) throws GameDoesNotExistException, InvalidCharacterException{ String game = gameAndLetter.getGame(); […]

不能在spring boot quartz中使用autowired feign client

我正在使用Netflix-OSS的 Spring启动它是一个很好的微服务系统,工作正常,我正在使用Feign Client ,以便在服务和Quartz之间建立连接以运行后台作业。 但是当我在工作中使用Autowired feign-client时会出现问题。 @FeignClient(value = “user”, configuration = {OAuthFeignConfig.class}, fallback = UserClientFallback.class) public interface UserClient { @RequestMapping(value = “/api/user/get/userName/{userName}”, method = RequestMethod.GET) UserInfoResponse getUserInfoByUserName(@PathVariable(“userName”) String userName); 和石英代码: public class DoJob extends RunnableTask { @Autowired private UserClient userClient; @Override public int run(JobExecutionContext jobExecutionContext) { userInfoById = userClient.getUserInfoById(“123e4567-e89b-12d3-a456-426655440000”); return userinfo.getIntId(); } } 和例外是: Error […]

java.lang.IllegalStateException:org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient中没有可用于学生服务的实例

我从link :: https://howtodoinjava.com/spring/spring-cloud/consul-service-registration-discovery/运行Spring Cloud Consule示例。 当我运行http:// localhost:8098 / getSchoolDetails / abcschool我收到以下错误,似乎客户端无法识别student-service 。 java.lang.IllegalStateException: No instances available for student-service at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(RibbonLoadBalancerClient.java:75) ~[spring-cloud-netflix-core-1.3.1.RELEASE.jar:1.3.1.RELEASE] at org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor.intercept(LoadBalancerInterceptor.java:55) ~[spring-cloud-commons-1.2.2.RELEASE.jar:1.2.2.RELEASE] at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:86) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.cloud.netflix.metrics.MetricsClientHttpRequestInterceptor.intercept(MetricsClientHttpRequestInterceptor.java:64) ~[spring-cloud-netflix-core-1.3.1.RELEASE.jar:1.3.1.RELEASE] at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:86) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:70) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:652) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:559) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE] at com.example.howtodoinjava.springcloudconsulschool.delegate.StudentServiceDelegate.callStudentServiceAndGetData(StudentServiceDelegate.java:22) ~[classes/:na] at […]