Tag: spring boot

使用Spring Boot执行器安全关闭rest服务器?

这是如何以正确的方式关闭Spring Boot应用程序的后续问题? 假设我们有一台服务器,当前连接了3个客户端,每个客户端都运行很长时间。 然后我们使用以下命令关闭服务器: curl -X POST localhost:port/shutdown 那样做: A)让服务器在关闭之前完成3个客户端正在运行的作业? B)禁止发生任何其他连接,以便服务器最终关闭?

Spring Boot:@Value返回null

我想使用application.properties文件中的值,以便在另一个类的方法中传递它。 问题是值返回NULL 。 可能是什么问题呢? 提前致谢。 application.properties filesystem.directory=temp FileSystem.java @Value(“${filesystem.directory}”) private static String directory;

用Spring Boot 2代替403而不是403

使用Spring Boot 1.5.6.RELEASE我能够发送HTTP状态代码401而不是403 ,如下所示: 如果请求uri未经身份validation , Spring Spring 安全响应未经授权(http 401代码) ,通过这样做: public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { //… http.exceptionHandling() .authenticationEntryPoint(new Http401AuthenticationEntryPoint(“myHeader”)); //… } } 使用org.springframework.boot.autoconfigure.security.Http401AuthenticationEntryPoint类。 我刚刚升级到Spring Boot 2.0.0.RELEASE ,发现不再有这样的类了(至少在那个包中)。 问: Spring Boot中是否存在此类( Http401AuthenticationEntryPoint )? 如果不是,那么在现有项目中保持相同行为以保持与依赖于此状态代码( 401 )而不是403其他实现的一致性的403什么?

使用Spring Boot启动JavaFX 2

我正在尝试使用JavaFX 2和Spring Boot创建新的应用程序,但到目前为止,由于MainPaneController的“root is null”,我的简单应用程序(如hello world)未运行。 MainPaneController类: public class MainPaneController implements Initializable { public static final String VIEW = “/fxml/Scene.fxml”; @FXML private Node root; @FXML private Label label; @PostConstruct public void init() { } public Node getRoot() { return root; } @FXML private void handleButtonAction(ActionEvent event) { System.out.println(“You clicked me!”); label.setText(“Hello World!”); } @Override public […]

设置JVM选项以避免错误org.springframework.cglib.core.ReflectUtils $ 1 非法reflection访问

我使用Spring Boot 2.0.0.RC1,JDK 9.0.4,IntelliJ IDEA 2017.3.4 Ultimate,Gradle 4.5.1。 Spring Boot RC1版本(严格来说,Spring Framework 5.0.3.RELEASE)有一个已知的问题: https ://jira.spring.io/browse/SPR-15859,我也在这里看到它https://github.com/ dsyer /弹簧引导java的9#创建-A-弹簧引导应用 Spring开发人员建议 您可以通过在命令行中添加-illegal-access = deny来关闭它(Java 9中的默认值是允许的)。 我选择菜单帮助\编辑自定义VM选项… ,然后在文件的最后一行添加新选项。 然后我发现了错误 > Unrecognized option: -illegal-access=deny > > Error: Could not create the Java Virtual Machine. > > Error: A fatal exception has occurred. Program will exit. Full console log /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin/java -XX:TieredStopAtLevel=1 […]

如何在spring boot中启用浏览器缓存

我正试图让Spring启动让浏览器缓存静态资源。 我的资源位于“静态”下的类路径中。 当我查看发回的标头时,我看到修改标头设置正常,但不知何故,标题“Cache-Control:no-store”也被添加。 HTTP/1.1 200 Last-Modified: Wed, 24 Aug 2016 08:50:16 GMT Cache-Control: no-store Accept-Ranges: bytes Content-Type: text/css Content-Length: 434554 Date: Wed, 24 Aug 2016 09:42:42 GMT 我已经看到了这个答案如何在Spring Boot中启用HTTP响应缓存 ,但这似乎并不适用于我,因为我没有使用spring-security,它不在类路径上。 我正在使用带有百里香的sp​​ring-boot 1.4.0。 那么,如何让spring boot不包含Cache-Control头?

将连接池与Jedis一起使用

我在rest服务中使用Jedis连接redis服务器。 当我调用Web服务时,我想做jedis.hmget , jedis.exits和hgetALL之类的操作 。 jedis.hmget(“employee:data:” + emp_user_id, “employee_id”).get(0); 我用于redis的配置是: Jedis jedis; JedisShardInfo shardInfo; @PostConstruct public void init() { try { shardInfo = new JedisShardInfo(Config.getRedisHost(), Config.getRedisPort()); shardInfo.setPassword(Config.getRedisPassword()); jedis = new Jedis(shardInfo); jedis.select(2); //jedis.se } catch (Exception e) { logger.error(“Exception in init ——- > ” + e); } } 我知道jedis不是线程安全的。当我一次使用1000个线程来调用服务时,我得到exception作为意外的流结束。 我开始知道jedis pool是线程安全但无法找到它的具体解决方案。 谢谢。 任何帮助,将不胜感激。

我不能在我的代码中使用findOne()方法

我的应用程序中有错误,因为我使用了findOne()方法。 在我的简单代码下面。 在User类中,我的id是String email,而我正在尝试在我的类UserService中使用id,如下所示: public User findUser(String email){ return userRepository.findOne(email); } 但我有这个错误: 接口org.springframework.data.repository.query.QueryByExampleExecutor中的方法findOne不能应用于给定的类型; 必需:org.springframework.data.domain.Example 发现:java.lang.String 原因:无法推断类型变量S(参数不匹配; java.lang.String无法转换为org.springframework.data.domain.Example) 用户类: @Entity @Data @Table(name = “User”) public class User { @Id @Email @NotEmpty @Column(unique = true) private String email; @NotEmpty private String name; @NotEmpty @Size(min = 5) private String password; @OneToMany(mappedBy = “user”, cascade = CascadeType.ALL) private List […]

如何使用jenkins将spring boot jar文件部署到EC2?

我正在尝试将Spring启动应用程序部署到AWS EC2实例。 我已经看到很多博客和教程完全解释了部署过程,这是可以理解的。 我正在努力如何在jenkins中进行持续部署或交付,其中主要function是春季启动应用程序名称或jar文件名称更改该时间。 我的管道 pipeline { agent any tools{ maven ‘localmaven’ } stages { stage(‘Build’) { steps { sh ‘mvn clean package’ } post { success { echo ‘Now Archiving…’ archiveArtifacts artifacts: ‘**/target/*.jar’ } } } stage(‘Deliver’) { steps { sh ‘scp -v -o StrictHostKeyChecking=no -i /var/lib/jenkins/secrets/mykey target/*.jar ubuntu@00.00.00.00:/home/ubuntu’ sh “sshpass -p password ssh […]

@WithUserDetails和spring boot 1.4 TestEntityManager问题

我有Spring Boot的TestEntityManager和@WithUserDetails注释的问题。 这是我的测试套件: public class AdvertisementAuthorizationTest extends AbstractIntegrationTest { private static final String IMPERSONATOR_EMAIL = “joe.hacker@gmail.com”; private final static String OWNER_OF_ADVERTISEMENT_EMAIL = “john.nice@gmail.com”; @Autowired private TestEntityManager testEntityManager; @Autowired private MockMvc mockMvc; private Advertisement advertisement; private UserAccount impersonator; private ObjectMapper mapper = new ObjectMapper(); @Before public void setUp() { advertisement = testEntityManager.persist(createAdvertisement(OWNER_OF_ADVERTISEMENT_EMAIL)); impersonator = testEntityManager.persist(createUserAccount(IMPERSONATOR_EMAIL)); } […]