Tag: spring boot

@DataJpaTest需要在测试之外的类

在SpringBoot应用程序中,我想对存储库层进行一些测试。 @RunWith(SpringRunner.class) @DataJpaTest public class VisitRepositoryTest { @Autowired private TestEntityManager entityManager; @Autowired private VisitRepository visitRepository; … } 当我尝试从VisitRepositoryTest运行测试时,我收到有关DefaultConfigService的错误 com.norc.Application中的字段defaultConfigService需要一个无法找到的类型为“com.norc.service.DefaultConfigService”的bean。 那么这需要运行Application吗? 我试图在VisitRepositoryTest放置一个DefaultConfigService bean,但是不允许这样做。 这个类在我的应用程序中使用 @EntityScan(basePackageClasses = {Application.class, Jsr310JpaConverters.class}) @SpringBootApplication @EnableScheduling public class Application implements SchedulingConfigurer { @Autowired private DefaultConfigService defaultConfigService; … } 如何管理? 编辑 在我的应用程序中,我在cron选项卡中使用此类: @Service public class DefaultConfigServiceImpl implements DefaultConfigService { private final DefaultConfigRepository defaultConfigRepository; […]

Spring Security – 白名单IP范围

我查看过的很多资源和stackoverflow问题都提供了使用.xml文件的答案: 使用Spring Security的IPfilter Spring Security 4 Method security using @PreAuthorize,@PostAuthorize, @Secured, EL http://docs.spring.io/spring-security/site/docs/3.0.x/reference/appendix-namespace.html#nsa-gms 我想知道的是,如果可以在不使用XML配置的情况下使用Spring Security将IP地址范围列入白名单? 以下是我的控制器中的一个简单方法: @RequestMapping(value = “/makeit”, method = RequestMethod.GET) @ResponseBody //@PreAuthorize(“hasIpAddress(‘192.168.0.0/16’)”) public String requestData() { return “youve made it”; } 我已经为安全配置创建了一个单独的类,但它没有太多,我只是为EnableGlobalMethodSecurity注释创建它 – 这样我就可以使用@PreAuthorize注释(来自这里的答案: @PreAuthorize注释不工作弹簧安全性 )。 @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) public class SpringConfiguration extends WebSecurityConfigurerAdapter { @Override public void configure(HttpSecurity http) throws […]

Maven从伟大的父母那里获取依赖版本,而不是我们父母的依赖管理

下面显示了我的POM的层次结构。 你可以看到我们有一个公司的父亲pom春季启动项目。 这个POM有spring-boot-starter作为它的父级,它导入我们自己的依赖管理BOM。 [INFO] — hierarchy-maven-plugin:1.4:tree (default-cli) @ user-service — [INFO] PARENT com.MY_COMPANY.platform:user:3.20.14-SNAPSHOT [INFO] PARENT com.MY_COMPANY.platform:spring-boot-parent:3.20.12-SNAPSHOT [INFO] PARENT org.springframework.boot:spring-boot-starter-parent:1.5.12.RELEASE [INFO] PARENT org.springframework.boot:spring-boot-dependencies:1.5.12.RELEASE <<<< This pom defines assertJ 2.x [INFO] [ other imports ] [INFO] IMPORT com.MY_COMPANY:dependencyManagementBase:2.23.14-SNAPSHOT <<<<<<<<<<<< This pom defines assertJ 3.x [INFO] IMPORT com.MY_COMPANY.platform:platform-dependency-management:1.20.7 [INFO] ———————————————————————— 为了专注于特定的,我们在依赖管理中定义AssertJ 3; 然而,spring-boot-dependencies定义了AssertJ 2.与assertJ没什么关系,但还有其他类似Mongo-Java-Driver的鱼没有拿起我们的版本。 Maven如何在这里选择优先权? 为什么我们的依赖管理不会战胜远祖的依赖管理? 我还注意到,如果我将AssertJ作为MY_COMPANY.platform:spring-boot-parent的依赖项添加,它也不会在我们的依赖管理中使用该版本(所以我现在只保留它,所以层次结构下显微镜更短)。 编辑 […]

springboot嵌入式tomcat和tomcat-embed-jasper

我有时会在pom.xml中看到以下声明…… org.springframework.boot spring-boot-starter-web javax.servlet jstl org.apache.tomcat.embed tomcat-embed-jasper provided …. 如您所见,spring-boot-starter-web被声明为tomcat-embed-jasper。 是不是spring-boot-starter-web已经有嵌入式tomcat? 为什么有些开发人员仍然使用boot-starter-web声明tomcat-embed-jasper? 或者有什么理由吗?

使用Spnego / Kerberos进行Spring启动 – 配置问题 – 需要ServletContext来配置默认的servlet处理

让spring-security-kerberos-web与Spring Boot应用程序一起工作,我似乎已经达到了一个死胡同。 我的项目中有一个@Configuration类,如下所示 package com.co.dept.bsc.configuration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.FileSystemResource; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.kerberos.authentication.KerberosAuthenticationProvider; import org.springframework.security.kerberos.authentication.KerberosServiceAuthenticationProvider; import org.springframework.security.kerberos.authentication.sun.GlobalSunJaasKerberosConfig; import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosClient; import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosTicketValidator; import org.springframework.security.kerberos.web.authentication.SpnegoAuthenticationProcessingFilter; import org.springframework.security.kerberos.web.authentication.SpnegoEntryPoint; import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; import com.co.dept.bsc.service.DummyUserDetailsService; @Configuration @EnableWebSecurity public class AuthProviderConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(final HttpSecurity http) throws Exception […]

如何记录Spring Boot中Rest Web服务所用的时间?

我正在使用Spring Boot编写Web Rest Web服务。 我想记录我的webservice处理请求所花费的时间。 另外我想记录调用的头文件,方法和URI。 几个月前我在我的jersey网络服务中使用ContainerRequestFilter and ContainerResponseFilter filter() method.做了类似的工作ContainerRequestFilter and ContainerResponseFilter filter() method. 另外,AOP更好还是过滤?

Spring Boot忽略logback-spring.xml

我有2个使用Logback的Spring Boot(1.4.1-RELEASE)控制台应用程序。 两个配置文件或多或少相同,位于my / src / main / resources文件夹中,名为logback-spring.xml 。 这两个项目都在其pom.xml中包含maven依赖spring-boot-starter-logging并获取logback Version 1.1.7。 两个poms中定义的Spring Boot配置: 4.0.0 org.springframework.boot spring-boot-starter-parent 1.4.1.RELEASE dmvapp-a my-app-a 1.0.16-SNAPSHOT jar org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-actuator org.springframework.boot spring-boot-starter-security org.springframework.boot spring-boot-starter-logging 但是,在运行应用程序时,其中一个似乎完全忽略了logback配置,而另一个则像预期的那样选择了它。 如果我为无法正常工作的应用程序将文件名更改为logback.xml ,它突然正常工作(即使使用我正在使用的弹簧配置文件)。 所涉及的任何配置(意味着pom.xml,application.properties等)没有明显差异。 有人知道为什么会这样吗? 我发现这种行为相当令人困惑。

Spring Boot CommandLineRunner:filter选项参数

考虑到Spring Boot CommandLineRunner应用程序,我想知道如何过滤传递给Spring Boot的“switch”选项作为外部化配置。 例如,用: @Component public class FileProcessingCommandLine implements CommandLineRunner { @Override public void run(String… strings) throws Exception { for (String filename: strings) { File file = new File(filename); service.doSomething(file); } } } 我可以调用java -jar myJar.jar /tmp/file1 /tmp/file2并且将为这两个文件调用该服务。 但是,如果我添加一个Spring参数,比如java -jar myJar.jar /tmp/file1 /tmp/file2 –spring.config.name=myproject那么配置名称会更新(正确!),但该服务也会调用文件./–spring.config.name=myproject当然不存在。 我知道我可以用类似的东西手动过滤文件名 if (!filename.startsWith(“–“)) … 但由于所有这些组件都来自Spring,我想知道是否有一个选项可以让它管理它,并确保传递给run方法的strings参数不会包含已在应用程序级别解析的所有属性选项。

Spring Boot + Thymeleaf ERROR java.lang.ClassNotFoundException:org.thymeleaf.dom.Attribute

我有使用Spring Boot和thymeleaf的以下问题,我无法解决它。 在错误发生后立即运行Application类时发生错误。 我与百里香的布局在于 主\资源\模板 HomeController的 @Controller public class HomeController { @GetMapping(“/”) public String root() { return “page/home”; } } 应用 @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } POM org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-data-jpa org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-starter-thymeleaf nz.net.ultraq.thymeleaf thymeleaf-layout-dialect org.springframework.boot spring-boot-devtools true LOG ERROR […]

java.io.IOException:无效的常量类型:19 at 5

我有一个项目 。 它使用spring boot 2 , java 9和maven。 它可以使用mvn clean package成功构建。 要运行spring boot应用程序,我使用了该命令 java -jar java-cloud-rest-api/target/java-cloud-rest-api-0.0.1-SNAPSHOT.jar 但它失败了,错误 org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘entityManagerFactory’ defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; n ested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1716) ~[spring-beans-5.0.0.RC3.jar!/:5.0.0.RC3] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.0.0.RC3.jar!/:5.0.0.RC3] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:499) ~[spring-beans-5.0.0.RC3.jar!/:5.0.0.RC3] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.0.RC3.jar!/:5.0.0.RC3] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) […]