Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Hello my app is deployed into Heroku which has limited number of database connections (20). This is why I need to watch carefully every opened connection. With my code number of connections from 0 reaches 10 after just refreshing the page. Why is that so? Here is my code:

package pl.jawegiel.springsecurityexample;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
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.crypto.bcrypt.BCryptPasswordEncoder;

import javax.sql.DataSource;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private DataSource dataSource;

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http
                .cors().and().csrf().disable()
                .authorizeRequests().antMatchers("/getUsersInfo")
                .fullyAuthenticated().and().httpBasic();

    }


    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.jdbcAuthentication().dataSource(dataSource).passwordEncoder(new BCryptPasswordEncoder())
                .usersByUsernameQuery("SELECT username, password, 'true' as enabled from users where username=?")
                .authoritiesByUsernameQuery("SELECT username, role FROM users WHERE username=?");
    }
}

in application properties:

spring.datasource.url=...
spring.datasource.platform=postgres
spring.datasource.username=...
spring.datasource.password=...

and my controller.java

@RestController
@CrossOrigin(origins = "*")
public class Controller {

    @Autowired
    private UserService userService;

    @GetMapping("/")
    public String abc() {
        return "abc";
    }

...

}

Could you tell me why there is so many connection and how to solve that? Is there anything you need else? Thank you in advance.

BEST ANSWER WILL BE MARKED AS ACCEPTED!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
2.6k views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...