Tag: spring boot

ResourceOwnerPasswordResourceDetails – 传递clientid和secret以生成oauth2令牌

我按照此问题中提到的接受的答案生成OAuth2令牌。 但是我收到HTTP 401响应。 当我调试时,我看到clientid和clientsecret不作为HTTP请求中表单的一部分传递。 我只看到下面列出的值被传递。 为了通过clientid和clientsecret ,我还应该做些什么吗? {grant_type=[password], username=[username], password=[password]}

如何使用Spring Boot加载外部配置?

我目前正在学习如何使用Spring Boot。 到目前为止,我从未使用像Spring这样的框架并直接使用文件(FileInputStream等) 所以情况就是这样:我有一些动态配置值,比如OAuth令牌。 我想在我的应用程序中使用它们,但我不知道如何用Spring实现这一点。 这是一些代码,以明确我正在搜索的内容: @Config(“app.yaml”) public class Test { @Value(“app.token”) private String token; private IClient client; public Test(String token) { this.client = ClientFactory.build(token).login(); } } 当然,这个例子很简单。 在这里,我想从YAML配置文件中动态获取值“token”。 此文件必须可供用户访问且不包含在JAR文件中。 我还发现doc: https : //docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html但我现在知道如何将它应用到我的项目中。 我怎么能得到这个? 先感谢您 :) 编辑: 以下是我的代码的一些部分: WatchdogBootstrap.java package de.onkelmorph.watchdog; import org.springframework.boot.Banner.Mode; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ImportResource; @SpringBootApplication @ImportResource(“classpath:Beans.xml”) public class WatchdogBootstrap […]

spring-boot-starter-parent在pom文件中做了什么?

我正在开发一个不是Spring boot而且还有spring mvc的项目。 我的意思是我在我的项目中没有这个类: @SpringBootApplication public class Application extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(Application.class, args); } 我有这三个类用于spring mvc的配置文件: @Import(WebSocketConfig.class) @Configuration @EnableWebMvc @ComponentScan(basePackages = “……”) public class MainConfiguration extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler(“/Content/**”) .addResourceLocations(“/Content/”); registry.addResourceHandler(“/Scripts/**”) .addResourceLocations(“/Scripts/”); } @Bean public InternalResourceViewResolver viewResolver() { InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); […]

如何让Spring Data处理多个异构DataSource?

我已成功使用Spring的Accessing Data With JPA教程。 我已经获得了自己的CrudRepository,只需配置一个特定的DataSource @Bean即可自动工作,并且这些内部连接由Spring Data(或Spring Boot管理,很难分辨哪个)。 但是,我无法弄清楚如何让自动化管道来处理第二个DataSource @Bean。 注入第二个会导致自动配置类在启动期间爆炸。 有关如何做到这一点的任何想法? 我为此做的搜索导致文章讨论了多个同类 DataSource用于负载平衡或其他目的,这实际上不是我需要的。 我有多个数据库,其中包含完全独立的内容,我需要将其引入此应用程序中,我真的希望避免因为第二个数据库进入混合而复制所有自动配置。 我希望这很简单,但我担心它在自动配置中是不受支持的边缘情况。

带有效证书的spring boot https获取ERR_SSL_VERSION_OR_CIPHER_MISMATCH,自签名工作正常

我正在运行Spring Boot 1.4.0.RELEASE。 我从我的IT部门获得了有效的证书。 我使用IT_cert.cer生成了一个tomcat keystore.jks文件 keytool -keystore tomcat-keystore.jks -storepass password -import -alias “tomcat” -file it_issued_cert.cer 配置我的application.yml打开SSL server: context-path: /uaa port: 9999 ssl: enabled: true key-store: classpath:tomcat-keystore.jks key-store-password: password key-password: password enabled-protocols: TLSv1.2 # make sure only to use the latest TLS version 用于签署证书的算法是 Signature algorithm name: SHA256withRSA 当我运行spring-boot应用程序时,它启动并找到我的证书。 当我在我的HTTPS端口上使用chrome时,浏览器不再出现“不受信任”警告。 但现在有一个来自Chrome和IE11的ERR_SSL_VERSION_OR_CIPHER_MISMATCH声称我可能正在使用RC4加密…… 我已经尝试指定低于TLSv1.2的非安全协议并采用默认值..但它们都会导致相同的错误。 我相信最新的Chrome / IE11有TLSv1.2所以我对浏览器的错误感到困惑。 […]

当两个应用程序都使用嵌入式activemq时,如何将Jms消息从一个spring-boot应用程序发送到另一个应用程序

我有两个spring-boot应用程序。 在receiver-application的Application.java中我有: @Bean public JmsListenerContainerFactory myFactory(ConnectionFactory connectionFactory, DefaultJmsListenerContainerFactoryConfigurer configurer) { DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory(); configurer.configure(factory, connectionFactory); return factory; } 在Receiver.java中…… @JmsListener(destination = “myQueue”, containerFactory = “myFactory”) public void receiveMessage(String tradeString) throws JSONException, IOException { tradeImpl = new ObjectMapper().readValue(tradeString, TradeImpl.class); } 在sender-application中我只使用: public void send(trade) { String queueName = “myQueue”; String tradeString = new ObjectMapper().writeValueAsString(trade); […]

如何使用Spring Boot配置嵌入式ActiveMQ Broker URL

我按照一个简单的例子来设置和运行带有Spring Boot的嵌入式ActiveMQ(版本1.4.X)。 这是示例https://spring.io/guides/gs/messaging-jms/的链接 我的课程结构如下: @SpringBootApplication @EnableJms public class Application { @Autowired ConfigurableApplicationContext context; @Bean JmsListenerContainerFactory myJmsContainerFactory(ConnectionFactory connectionFactory) { SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory(); factory.setConnectionFactory(connectionFactory); return factory; } @JmsListener(destination = “mailbox-destination”, containerFactory = “myJmsContainerFactory”) public void receiveMessage(String message) { System.out.println(“Message received: ” + message); context.close(); } public static void main(String[] args) throws Exception { FileSystemUtils.deleteRecursively(new File(“active-data”)); […]

Spring JPA存储库:阻止保存更新

我的user数据库表如下所示: CREATE TABLE user ( username VARCHAR(32) PRIMARY KEY, first_name VARCHAR(256) NOT NULL, last_name VARCHAR(256) NOT NULL, password VARCHAR(32) NOT NULL, enabled BOOL ) ENGINE = InnoDB; 这是我的实体的字段定义: @Entity public class User implements Serializable { private static final long serialVersionUID = 1L; @Id @Column(nullable = false) private String username; @Column(nullable = false) private String firstName; […]

@Around @Aspect在同一个包中仅适用于@DependsOn

请参阅以下更新。 我有一个Spring Boot应用程序,我接受TCP / IP连接: public MyClass implements InitializingBean { @Override public void afterPropertiesSet() throws Exception { try (ServerSocket serverSocket = new ServerSocket(port)) { while (true) { Socket socket = serverSocket.accept(); new ServerThread(socket).start(); } } } … private class ServerThread extends Thread { @Override public void run() { try (InputStream input = socket.getInputStream(); OutputStream output […]

春季启动。 HMAC认证。 如何添加自定义AuthenticationProvider和身份validationfilter?

为了实现HMAC身份validation,我创建了自己的filter,提供者和令牌。 RestSecurityFilter: public class RestSecurityFilter extends AbstractAuthenticationProcessingFilter { private final Logger LOG = LoggerFactory.getLogger(RestSecurityFilter.class); private AuthenticationManager authenticationManager; public RestSecurityFilter(String defaultFilterProcessesUrl) { super(defaultFilterProcessesUrl); } public RestSecurityFilter(RequestMatcher requiresAuthenticationRequestMatcher) { super(requiresAuthenticationRequestMatcher); } @Override public Authentication attemptAuthentication(HttpServletRequest req, HttpServletResponse response) throws AuthenticationException, IOException, ServletException { AuthenticationRequestWrapper request = new AuthenticationRequestWrapper(req); // Get authorization headers String signature = request.getHeader(“Signature”); String […]