Tag: spring boot

在Weblogic中部署Spring Boot应用程序

我在webLogic 12C中部署Spring启动应用程序时遇到了麻烦。 10.4.4 403禁止服务器理解请求,但拒绝履行请求。 授权无效,请求不应重复。 如果请求方法不是HEAD并且服务器希望公开为什么请求没有得到满足,那么它应该描述实体中拒绝的原因。 当服务器不希望确切地说明请求被拒绝的原因,或者没有其他响应适用时,通常会使用此状态代码。 我想知道是否有人可以提供帮助。

如何在Spring Boot应用程序中配置嵌入式MongDB进行集成测试?

我有一个相当简单的Spring Boot应用程序,它公开一个小的REST API并从MongoDB的一个实例中检索数据。 对MongoDB实例的查询通过基于Spring Data的存储库进行。 下面的一些关键代码。 // Main application class @EnableAutoConfiguration(exclude={MongoAutoConfiguration.class, MongoDataAutoConfiguration.class}) @ComponentScan @Import(MongoConfig.class) public class ProductApplication { public static void main(String[] args) { SpringApplication.run(ProductApplication.class, args); } } // Product repository with Spring data public interface ProductRepository extends MongoRepository { Page findAll(Pageable pageable); Optional findByLineNumber(String lineNumber); } // Configuration for “live” connections @Configuration public class […]

如何将基于方法的安全性添加到Spring Boot项目?

我想为Spring Boot项目添加基于方法的安全性。 似乎我只需要添加PermissionEvaluator和MethodSecurityExpressionHandler bean,使用@EnableGlobalMethodSecurity(prePostEnabled = true)注释我的WebSecurityConfigurerAdapter ,使用@PreAuthorize(“isAuthenticated() and hasPermission(#param, ‘somePermissionName’)”) 。 但是在添加PermissionEvaluator bean之后 @Bean public PermissionEvaluator permissionEvaluator() { HelloPermissionEvaluator bean = new HelloPermissionEvaluator(); return bean; } 我得到一个IllegalArgumentException :“需要一个ServletContext来配置默认的servlet处理”: Exception in thread “main” org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘defaultServletHandlerMapping’ defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method […]

Spring Boot + Oauth2客户端凭据

我正在尝试使用带有客户端凭据流的Oath2来保护我在Spring Boot上的微服务。 顺便说一句,那些微服务只会通过中间件层互相交谈,我的意思是不需要用户凭证来允许授权(用户登录过程如Facebook)。 我在Internet上查找了示例,了解如何创建授权和资源服务器来管理此通信。 但是我刚刚找到了解释如何使用用户凭据(三条腿)来解释它的示例。 有没有人有任何示例如何在Spring Boot和Oauth2中做到这一点? 如果可以提供有关所使用范围的更多详细信息,则令牌交换将不胜感激。

无法在不同的Spring启动应用程序中的不同端口上启动2个嵌入式active-mq

我有2个弹簧启动应用程序。 每个应用程序都嵌入了活动的mq代理。 我需要并行处理同一台PC上的2个应用程序,但它现在不起作用。 第一个应用程序始终成功启 2018-02-02 11:48:20.095 INFO 7660 — [ main] scaAnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@53045c6c: startup date [Fri Feb 02 11:48:20 MSK 2018]; root of context hierarchy 2018-02-02 11:48:20.923 INFO 7660 — [ JMX connector] oaabroker.jmx.ManagementContext : JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:7777/jmxrmi 2018-02-02 11:48:20.923 INFO 7660 — [ main] o.apache.activemq.broker.BrokerService : Using Persistence Adapter: […]

如何在Spring Boot中以编程方式创建bean?

我有一个应用程序,其中包含application.properties中列出的许多数据源设置。 我有一个@ConfigurationProperties类来加载这些设置。 现在我想从这个ConfigurationProperties类中获取值,并使用它们即时创建DataSource bean。 我尝试过使用@PostConstruct并实现BeanFactoryPostProcessor 。 但是,使用BeanFactoryPostProcessor ,处理似乎很早就发生了 – 在我的ConfigurationProperties类已经填充之前。 如何使用Spring Boot快速读取属性并创建DataSource bean? 这是我的application.properties的样子: ds.clients[0]=client1|jdbc:db2://server/client1 ds.clients[1]=client2,client3|jdbc:db2://server/client2 ds.clients[2]=client4|jdbc:db2://server/client4 ds.clients[3]=client5|jdbc:db2://server/client5 我的ConfigurationProperties类: @Component @ConfigurationProperties(prefix = “ds”) public class DataSourceSettings { public static Map CLIENT_DATASOURCES = new LinkedHashMap(); private List clients = new ArrayList(); public List getClients() { return clients; } public void setClients(List clients) { this.clients = clients; […]

在Spring Boot 1.4中测试安全性

我正在尝试使用SecurityConfig类中定义的自定义安全设置来测试@WebMvcTest : @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests().antMatchers(“/admin*”).access(“hasRole(‘ADMIN’)”).antMatchers(“/**”).permitAll().and().formLogin(); } @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication().withUser(“user”).password(“password”).roles(“ADMIN”); } } 测试类是: @RunWith(SpringRunner.class) @WebMvcTest(value = ExampleController.class) public class ExampleControllerMockMVCTest { @Autowired private MockMvc mockMvc; @Test public void indexTest() throws Exception { mockMvc.perform(get(“/”)) .andExpect(status().isOk()) .andExpect(view().name(“index”)); } […]

如何在Spring Boot项目中禁用Hibernatevalidation

我有一个spring boot项目,它有一个CrudRepository,一个Entity和一个Controller。 我基本上试图根据传递给Controller的数据来持久化实体。 为此,我使用的是spring-boot-starter-jpa 。 我的实体使用JSR-303注释进行注释, 在将数据传递给CrudRepository以进行持久化之前 ,在控制器中对其进行检查。 控制器方法: @RequestMapping(value = “users”, method = { RequestMethod.POST }) public SuccessfulResponse addUser(@Valid @RequestBody User user, BindingResult validation) { if (validation.hasErrors()) { throw new ValidationException(validation); } User saved = this.users.save(user); return new SuccessfulResponse(saved); } 实体: @Entity /* JPA */ public class User { @Id /* JPA */ @Column(name=”email_address”, […]

Spring Boot – 环境@Autowired抛出NullPointerException

我使用Spring Boot 0.5.0.M5进行项目设置。 在其中一个配置文件中,我尝试使用@Autowire Environment但是因为NullPointerException而失败。 这是我到目前为止所拥有的: Application.java @EnableAutoConfiguration @Configuration @ComponentScan public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } JpaConfig.java我正在尝试@Autowire Environment @Configuration @EnableTransactionManagement @EnableJpaRepositories(basePackages = “com.ui.persistence.repository”) public class JpaConfig { private static final String DATABASE_DRIVER = “db.driver”; private static final String DATABASE_PASSWORD = “db.password”; private static final String DATABASE_URL = […]

可以使用属性启用/禁用弹簧启动@RestController吗?

给出带有@RestController的“标准”spring引导应用程序,例如 @RestController @RequestMapping(value = “foo”, produces = “application/json;charset=UTF-8”) public class MyController { @RequestMapping(value = “bar”) public ResponseEntity bar( return new ResponseEntity(“Hello world”, HttpStatus.OK); } } 是否存在注释或技术,如果/除非某个应用程序属性存在/不存在,则会阻止端点启动。 注意:测试方法内的属性并爆炸不是解决方案,因为端点将存在。 我不关心粒度:即启用/禁用方法或整个类都很好。 由于配置文件不是属性,因此通过配置文件进行控制并不能解决我的问题。