小编mps*_*tos的帖子

带Jersey的Spring Boot 2.1.0

今天我开始了一个简单的应用程序spring boot应用程 因为我从头开始,我使用的是最新版本的SpringBoot:2.1.0.RELEASE

我想使用Jersey来使用JAX-RS.我有这个适用于1.3.6 Spring Boot版本,但是我收到以下错误:

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'requestContextFilter', defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.class] and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
Run Code Online (Sandbox Code Playgroud)

我无法理解问题出在哪里,因为我此时的应用程序极简主义.

显然bean'requestContextFilter'正在配置两次,但我不知道它在哪里配置.

这是我的配置:

的pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.0.RELEASE</version>
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <start-class>pt.msoftware.userauthservice.App</start-class>
    <java.version>1.8</java.version>
    <docker.image.prefix>${user.name}</docker.image.prefix>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>

    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId> …
Run Code Online (Sandbox Code Playgroud)

jersey spring-boot

9
推荐指数
1
解决办法
2523
查看次数

Angular 7-如何分隔不同目录中的文件

我正在将Angular 7应用程序配置为生产环境,并尝试在不同目录中组织文件。

angular.json

            "architect": {
                "build": {
                    "builder": "@angular-devkit/build-angular:browser",
                    "options": {
                        "outputPath": "dist/samsara-ui",
                        "index": "src/index.html",
                        "main": "src/js/main.ts",
                        "polyfills": "src/js/polyfills.ts",
                        "tsConfig": "src/tsconfig.app.json",
                        "assets": [
                            "src/favicon.ico",
                            "src/assets"
                        ],
                        "styles": [
                            "src/styles.css",
                            "src/samsara-theme.scss"
                        ],
                        "scripts": []
                    },
Run Code Online (Sandbox Code Playgroud)

目前,我的目录如下所示:

??? dist
|   ??? <appname>
|   |   ??? assets
|   |   |   ??? icons
|   |   |   ??? images

|   |   |   index.html
|   |   |   *.js (bundled files: runtime.js, polyfills.js, vendor.js, main.js)
|   |   |   *.map
|   |   |   style.css
|   |   |   *.woff, …
Run Code Online (Sandbox Code Playgroud)

angular-cli angular angular7

8
推荐指数
1
解决办法
120
查看次数

Spotless + Java Google 格式与 Intellij + 导入文件

我正在尝试配置 Maven Spring Boot 应用程序以使用具有 google java 格式样式的一尘不染。我也希望 Intellij 像 Maven 插件一样格式化代码。

但我注意到应用的格式略有不同。

举个例子:Intellij不会改变下面两行

@Mock 
private UserRepository userRepositoryMock;
Run Code Online (Sandbox Code Playgroud)

但是maven插件(使用命令:mvn Spotless:apply)将格式化如下:

@Mock private UserRepository userRepositoryMock;
Run Code Online (Sandbox Code Playgroud)

项目管理配置

<plugin>
                <groupId>com.diffplug.spotless</groupId>
                <artifactId>spotless-maven-plugin</artifactId>
                <version>${spotless.version}</version>
                <configuration>
                    <!-- optional: limit format enforcement to just the files changed by this feature branch -->
                    <ratchetFrom>origin/master</ratchetFrom>
                    <formats>
                        <!-- you can define as many formats as you want, each is independent -->
                        <format>
                            <!-- define the files to apply to -->
                            <includes>
                                <include>*.md</include>
                                <include>.gitignore</include>
                            </includes>
                            <!-- define the steps to apply …
Run Code Online (Sandbox Code Playgroud)

java maven google-java-format spotless

8
推荐指数
1
解决办法
6277
查看次数

Hibernate:初始化与取消代理

我遇到了多对多问题

@ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
@JoinTable(
    name = "PORTFOLIO_USER_PERMS",
    joinColumns = { @JoinColumn(name = "USERNAME") },
    inverseJoinColumns = { @JoinColumn(name = "PORTFOLIO_ID"), }
)
private List<Portfolio> sharedPortfolios = new ArrayList<>();
Run Code Online (Sandbox Code Playgroud)

我有一种情况,其中sharedPortfolios 的一个元素之一是代理,另一个元素具有一个代理属性(由于一对一关系,actulay 是同一个对象)。该列表通常返回到控制器方法,然后转换为相应的 DTO。正如您可能怀疑的那样,带有代理对象的单个属性导致了LazyInitializationException

在此输入图像描述

这意味着在服务中,我需要遍历列表中的每个元素,查找可能是使用 Hibernate 实用程序进行代理和取消代理的任何属性:Hibernate.unproxy(...),然后再将其传递给控制器​​。

我的问题:

1) Hibernate.initializeHibernate.unproxy之间有什么区别?

初始化代理对象并不能解决问题。

2)为什么其中一个元素是代理,而其他元素不是?

3)除了手动遍历这个列表和所有属性并搜索代理对象之外,还有什么更好的方法呢?

太感谢了。

此致。

java hibernate

7
推荐指数
1
解决办法
2185
查看次数

Angular Flex 布局:圣杯设计

我正在尝试使用 Angular Flex Layout 创建一个简单的页面。(实际上我正在从应用程序中删除 Bootstrap,因为我使用的是 Angular Material 并且觉得混合它们不是一件好事)。我的目标是通过只有页眉、内容和页脚来使用“圣杯布局”设置主页。

|------------------------------------|
|              Header                |
|------------------------------------|
|                                    |
|              Content               |
|                                    |
|------------------------------------|
|              Footer                |
|------------------------------------|
Run Code Online (Sandbox Code Playgroud)

以下是代码

应用程序组件.html

<div class="main-container" fxLayout="column">
  <div fxFlex="none">
    <app-header></app-header>
  </div>
    <div fxFlex>
      <router-outlet></router-outlet>
    </div>
  <div fxLayout="row" fxLayoutAlign="start end">
    <div fxFlex>
      <app-footer></app-footer>
    </div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

应用组件.css

.main-container {
  min-height: 100vh;
  border:1px solid black;
}
Run Code Online (Sandbox Code Playgroud)

主页.component.html

<div>
  home works!
</div>
Run Code Online (Sandbox Code Playgroud)

主页.component.css

div {
  margin: 1px 0px 1px 0px;
  padding: 1px;
  border: 1px solid blue;
  height: 100%;
} …
Run Code Online (Sandbox Code Playgroud)

angular-flex-layout angular

5
推荐指数
1
解决办法
3874
查看次数

JDBC 查询与 JPA 查询性能

从数据库读取数千条记录时,我遇到了一些与性能相关的问题。我注意到纯 JDBC 查询比 JPA 本机查询快得多。

这是查询

select ID, COL_A, COL_B, COL_C, COL_D, COL_E, COL_F from MY_SUPER_VIEW_V v 
where 1=1 
and v.ID in (:idList)
and v.DATE_FROM <= :date
and v.DATE_TILL >= :date;
Run Code Online (Sandbox Code Playgroud)

此查询返回大约 38.000 条记录。

in idList 有超过 1000 条记录,因为我使用的是 Oracle DB,所以需要拆分为 n 个查询。

此外,我有一种方法可以将 Object[] 结果转换为我的List<Entity>.

为了理解性能问题,我分别创建了一个纯 JDBC 查询和一个 JPA Native 查询来比较结果。

以下是时间安排。

################ getScoresPureJDBCWithListIds ################
List of Ids retrieved. It took: 00:00:00.096 to execute query on DB using JDBC
It took: 00:00:01.180 to execute query on DB …
Run Code Online (Sandbox Code Playgroud)

java hibernate jpa jdbc

5
推荐指数
1
解决办法
2012
查看次数

Angular Material - mat-select:自定义填充溢出父元素

我正在使用 Angular Material 组件,并且正在尝试自定义组合框(选择)。当我更改组件的填充时,它会溢出包装 div 元素。我期待它一起成长。

添加填充前的外观

在此处输入图片说明

添加填充后的外观 在此处输入图片说明

正如我们所看到的,当 mat-select 元素通过添加填充来增加其宽度时,mat-select div 没有增长

html代码

<div style="border: 1px solid black; min-width: 100px; margin: 0px 5px; float: left">
    <mat-form-field class="my-select template-select">
        <mat-select [(value)]="templateSelected">
            <mat-select-trigger>
                <div fxLayoutAlign="start center">
                    <i fxFlex="none" class="material-icons md-dark">visibility</i>
                    <span fxFlex>{{templateSelected}}</span>
                </div>
            </mat-select-trigger>
            <mat-option value="Full data">
                <div fxLayoutAlign="start center" class="template-option">
                    <i fxFlex="none" class="material-icons md-dark">done</i>
                    <span fxFlex>Full data</span>
                </div>
            </mat-option>
            <mat-option value="My quarterly report">
                <div fxLayoutAlign="start center" class="templateOption">
                    <i fxFlex="24px" class="material-icons md-dark"></i>
                    <span fxFlex>My quarterly report</span>
                </div> …
Run Code Online (Sandbox Code Playgroud)

html css angular-material angular

4
推荐指数
1
解决办法
4693
查看次数

Spring Security UsernamePasswordAuthenticationFilter:登录失败后如何访问Request

我正在使用 Angular 7 和 Spring Boot 实现一个登录页面,并且正在处理登录失败。基本上我想在 X 次登录尝试失败后锁定登录一段特定的时间。

Http安全配置

@Override
    protected void configure(HttpSecurity http) throws Exception {
        logger.info("#### Configuring Security ###");
        JWTAuthenticationFilter jwtAuthenticationFilter = new JWTAuthenticationFilter(authenticationManager());
        jwtAuthenticationFilter.setFilterProcessesUrl("/rest/users/authenticate");//this override the default relative url for login: /login

        http
            .httpBasic().disable()
            .csrf().disable()
            .authorizeRequests()
            .antMatchers("/rest/", "/rest/helloworld/**").permitAll()
            .anyRequest().authenticated()
            .and().exceptionHandling().authenticationEntryPoint(new JwtAuthenticationEntryPoint()).and()
            .addFilter(jwtAuthenticationFilter);
Run Code Online (Sandbox Code Playgroud)

为了处理登录,我创建了一个过滤器

public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
    private static Logger logger = Logger.getLogger(JWTAuthenticationFilter.class);

    private AuthenticationManager authenticationManager;

    public JWTAuthenticationFilter(AuthenticationManager authenticationManager) {
        this.authenticationManager = authenticationManager;

    }

    @Override
    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { …
Run Code Online (Sandbox Code Playgroud)

spring spring-security

3
推荐指数
1
解决办法
2906
查看次数

Spring Data:JPA 和嵌套事务

我在 Spring JPA 数据和嵌套事务方面遇到问题。以下是我的服务的嵌套事务的两种方法。

@Service
public UserService {

    @Transactional
    public User createUser(UserDto userDto) {
        ....
        user = saveUser(user);
        sendEmail(user);
        ....
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public User saveUser(User user) {
        return userRepository.save(user);
    }
Run Code Online (Sandbox Code Playgroud)

碰巧有一种情况,方法 userRepository.save() 应该抛出异常,但不知何故没有被抛出,看起来它正在等待父事务完成。我预计 saveUser 方法会抛出异常,而 sendEmail 方法甚至不会被执行。

因为该方法UserService.saveUser将传播设置为Propagation.REQUIRES_NEW我期望提交事务(要执行的 SQL 语句)并且传播任何异常。

我没有设置任何与事务相关的内容,所以我相信刷新模式设置为自动。

谁能发现我做错了什么或者我的误解是什么?

java spring jpa spring-data-jpa kotlin

1
推荐指数
1
解决办法
3154
查看次数