Tag: spring boot

H2嵌入DB,弹出启动错误自动配置

我正在尝试使用带有弹簧靴的H2嵌入式DB。 但是,它会引发以下错误。 2016-10-19 22:05:25.818 INFO 14104 — [ main] com.example.SpringDemoApplication : Starting SpringDemoApplication on BOM1-LPMP12AS7U with PID 14104 (D:\workspace\eclipse\SpringDemo\target\classes started by e3028311 in D:\workspace\eclipse\SpringDemo) 2016-10-19 22:05:25.822 INFO 14104 — [ main] com.example.SpringDemoApplication : No active profile set, falling back to default profiles: default 2016-10-19 22:05:25.904 INFO 14104 — [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@543e710e: startup […]

Apache Shiro的Spring Boot

我目前正在尝试将Apache Shiro集成到我的Spring Boot restful API中,但我遇到了一些问题,并且想知道是否有人可以提供帮助。 我的Application.class: @Configuration @EnableTransactionManagement @EnableAutoConfiguration @ComponentScan(basePackages = “org.xelamitchell.sophia.server”) public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } 我的WebConfig.class: @Configuration @EnableWebMvc public class WebConfig extends WebMvcConfigurerAdapter { @Bean public DispatcherServlet dispatcherServlet() { DispatcherServlet servlet = new DispatcherServlet(); servlet.setDispatchOptionsRequest(true); return servlet; } @Bean public ServletRegistrationBean dispatcherRegistration(DispatcherServlet dispatcherServlet) { […]

在不定义其他模块的情况下,使用Spring JAXB Marshaller和Java 9的正确方法

为了说明我的问题,我创建了一个小的spring boot示例应用程序。 该应用程序的目的是创建一个Jaxb2Marshaller bean。 @SpringBootApplication public class App implements CommandLineRunner { public static void main(String[] args) { SpringApplication.run(App.class, args); } @Bean public Jaxb2Marshaller jaxb2Marshaller() { Jaxb2Marshaller bean = new Jaxb2Marshaller(); bean.setContextPath(“ch.sahits.game.helloworld”); return bean; } @Override public void run(String… args) throws Exception { System.out.println(“Started up”); } } 此代码无法启动exception: Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185) […]

Spring MVC with Boot:“出现意外错误(type = Not Found,status = 404)”

所以我是Spring的新手,到目前为止我已经运行了一个连接到MongoDB数据库的简单Web API,但是我在使用.jsp或.html文件生成普通的旧视图时遇到了麻烦。 我尝试了各种不同的方法: InternalResourceViewResolver , XmlViewResolver ,返回Strings而不是ModelAndView对象,似乎没有什么对我XmlViewResolver 。 我有以下代码: 编辑 :这是我的项目的一个git repo: https : //github.com/jwallp/Spring-Test 正如上面的项目所示,我在转到/index时遇到了白标错误: There was an unexpected error (type=Internal Server Error, status=500). Circular view path [index]: would dispatch back to the current handler URL [/index] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to […]

Springboot REST应用程序应该接受并生成XML和JSON

我正在开发Springboot REST API。 我的应用程序应该使用并生成XML和JSON。 我遇到了Jackson json Xml的依赖。 com.fasterxml.jackson.dataformat jackson-dataformat-xml 2.5.4 我在我的pom.xml中添加了这个。 现在我能够接受xml输入,但映射到Java Object时值为null。 以下是我的资源类。 @Configuration @ImportResource(“/application-context.xml”) @EnableAutoConfiguration @ResponseBody @RequestMapping(“/match”) public class MatchResource { private static final Logger logger = LogManager.getLogger(MatchResource.class); @Autowired private MatchService matchService; @RequestMapping(method = RequestMethod.POST) @Consumes({MediaType.TEXT_XML,MediaType.APPLICATION_JSON}) @Produces({MediaType.TEXT_XML,MediaType.APPLICATION_JSON}) //@Produces( MediaType.APPLICATION_XML) public Response matchRequest(@RequestBody MatchRequest matchRequest, @Context HttpServletRequest headers) throws Exception { Response resp = […]

如何自定义Spring Boot AccessTokenProvider?

我想增强OAuth2提供程序的令牌请求。 我需要在POST请求中添加一个额外的参数。 我不明白在哪里挂钩Spring Boot框架来实现这一目标。 Spring Boot框架提供了一个用于自定义OAuth2RestTemplate的钩子,如“ 自定义用户信息RestTemplate ”中所述。 我已经实现了以下定制器,它被实例化并按预期调用。 不幸的是,在提出令牌请求时似乎没有调用我的提供程序。 public class AadUserInfoRestTemplateCustomizer implements UserInfoRestTemplateCustomizer { @Override public void customize(OAuth2RestTemplate oAuth2RestTemplate) { oAuth2RestTemplate.setAuthenticator(new AadOauth2RequestAuthenticator()); // Attempt 1: Use my own token provider, but it never gets called… oAuth2RestTemplate.setAccessTokenProvider(new AadAccessTokenProvider()); // Even better, if only OAuth2RestTemplate provided a getter for AccessTokenProvider, I could add interceptors and […]

配置Activiti以重用Spring Boot中的现有用户/组数据

我正在使用Spring Boot 1.4.3.RELEASE。 我已经创建了一个简单的MVC应用程序来管理用户和组。 现在,我正在尝试将Activiti 5.21.0集成到我的项目中,并重新使用 Activiti的现有用户/组表。 我已经从Activiti扩展了默认的UserEntityManager和GroupEntityManager类,如下所示: CustomUserEntityManager.java import java.util.List; import org.activiti.engine.impl.Page; import org.activiti.engine.impl.UserQueryImpl; import org.activiti.engine.impl.persistence.entity.IdentityInfoEntity; import org.activiti.engine.impl.persistence.entity.UserEntity; import org.activiti.engine.impl.persistence.entity.UserEntityManager; import com.example.spring.dao.UserDao; import com.example.spring.model.User; public class CustomUserEntityManager extends UserEntityManager { private UserDao userDao; public CustomUserEntityManager(UserDao userDao) { this.userDao = userDao; } @Override public UserEntity findUserById(String userId) { User user = userDao.findById(Integer.parseInt(userId)); return userToActivitiUser(user); } […]

根据spring jpa中的实体从多个表中获取数据

我有三个实体,如下所示: 注释: @Entity @Table(name = “comments”) public class CommentBean implements Serializable { @Id @Column(name = “id”) @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @Column(name = “commentId”) private long commentId; @Column(name = “topicId”) private String topicId; } 话题: @Entity @Table(name = “topics”) public class TopicBean implements Serializable { @Id @Column(name = “id”) @GeneratedValue(strategy = GenerationType.AUTO) private Long […]

为可信空间定制Spring Security

服务在可信空间中的网关之后工作(gateWayvalidationOAuth令牌并仅向服务提供唯一的用户ID,其他情况下它重定向以validation服务)。 我想在服务中使用spring security来validationuserId的权限。 所以我添加了CustomUserDetailsService @Service( “的UserDetailsS​​ervice”) 公共类CustomUserDetailsS​​ervice实现UserDetailsS​​ervice { @Autowired(required = false) private ContextSsoActiveProfileIdProvider contextSsoActiveProfileIdProvider; @Autowired private GrantedAuthorityService grantAuthorityService; @覆盖 public User loadUserByUsername(final String username)throws UsernameNotFoundException { //使用身份validation服务validation它,但没有令牌,仅限userId,因此信任网关服务。 返回新用户( 将String.valueOf(contextSsoActiveProfileIdProvider.getSsoActiveProfileId()), “authenticatedWithGateWay” grantedAuthorityService.getGrantedAuthoritiesForCurrentUser() ); } } 其中contextSsoActiveProfileIdProvider.getSsoActiveProfileId()返回uniqueUserId和grantedAuthorityService.getGrantedAuthoritiesForCurrentUser()返回权限。 该服务在受信任区域中启动,因此我已通过下一步方式配置安全性: @EnableWebSecurity @组态 公共类SecurityConfiguration扩展了WebSecurityConfigurerAdapter { @Autowired private UserDetailsS​​ervice userDetailsS​​ervice; @覆盖 protected void configure(HttpSecurity http)抛出Exception { HTTP .authorizeRequests() .antMatchers( “/ **”)permitAll(); […]

Spring Boot生产监控

Spring Boot Actuator公开了部署容器的许多指标和信息。 然而,生产操作人员可能不想在他们的浏览器上盯着纯JSON对象:) 什么是用于监控生产的好“标准”工具? 这将包括图表,警报触发器等。