小编Gus*_*avo的帖子

使用Tomcat启动Spring Boot时的用户名和密码是什么?

当我通过Spring Boot和访问部署我的Spring应用程序时,localhost:8080我必须进行身份验证,但是用户名和密码是什么,或者我如何设置它?我试图将此添加到我的tomcat-users文件但它不起作用:

<role rolename="manager-gui"/>
    <user username="admin" password="admin" roles="manager-gui"/>
Run Code Online (Sandbox Code Playgroud)

这是应用程序的起点:

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是Tomcat依赖:

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

我该如何进行身份验证localhost:8080

java spring tomcat spring-mvc spring-boot

118
推荐指数
4
解决办法
15万
查看次数

如何在spring boot中从一个安静的控制器返回一个html页面?

我想从控制器返回一个简单的html页面,但我只得到文件的名称而不是它的内容.为什么?

这是我的控制器代码:

@RestController
public class HomeController {

    @RequestMapping("/")
    public String welcome() {
        return "login";
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的项目结构:

[在此输入图像描述

html java spring controller spring-boot

15
推荐指数
7
解决办法
6万
查看次数

如何向假装客户端添加请求拦截器?

每当我通过假装客户端发出请求时,我都希望为我的身份验证用户设置一个特定的标头.

这是我的过滤器,我从中获取身份验证并将其设置为spring安全上下文:

@EnableEurekaClient
@SpringBootApplication
@EnableFeignClients
public class PerformanceApplication {
    @Bean
    public Filter requestDetailsFilter() {
        return new RequestDetailsFilter();
    }

    public static void main(String[] args) {
        SpringApplication.run(PerformanceApplication.class, args);
    }

    private class RequestDetailsFilter implements Filter {
        @Override
        public void init(FilterConfig filterConfig) throws ServletException {

        }

        @Override
        public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
            String userName = ((HttpServletRequest)servletRequest).getHeader("Z-User-Details");
            String pass = ((HttpServletRequest)servletRequest).getHeader("X-User-Details");
            if (pass != null)
                pass = decrypt(pass);
            SecurityContext secure = new SecurityContextImpl();
            org.springframework.security.core.Authentication token = new UsernamePasswordAuthenticationToken(userName, …
Run Code Online (Sandbox Code Playgroud)

java authentication spring header feign

9
推荐指数
2
解决办法
2万
查看次数

如何在Spring启动应用程序中将用户添加到嵌入式tomcat?

我正在尝试创建一个Spring启动应用程序,一切运行正常,除非我必须在访问localhost时插入用户名和密码:8080.我不知道如何从我的应用程序添加新的tomcat用户到嵌入式tomcat.

这是我的pom xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mastercrafters</groupId>
    <artifactId>mastercrafters</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>mastercrafters</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.0.BUILD-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

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

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url> …
Run Code Online (Sandbox Code Playgroud)

java spring tomcat maven spring-boot

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

如何在Java中处理PSQLException?

我对我的一个实体有一个唯一的约束,每当我收到一个PSQLException时,只要违反该约束,就会发生一个错误请求,我想用一个错误的请求来响应。

这是我尝试实现的异常处理程序:

@ControllerAdvice
public class DatabaseExceptionHandler {
    @ExceptionHandler(value = PSQLException.class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public void handleDatabaseExceptions(PSQLException e) {
        // i want to respond with a bad request only when this condition is satisfied
//
//        if (e.getSQLState().equals("23505")) {
//
//        }
    }

}
Run Code Online (Sandbox Code Playgroud)

这是将模型保存在db中的位置:

 public DepartmentForHoliday setDepartment(DepartmentForHoliday department) {
        if (department.getDepartmentId() == null) {
            Department savedDepartment = new Department();
            savedDepartment.setName(department.getName());
            try {
                departmentRepository.save(savedDepartment);
            } catch (PSQLException e) {
              /*here i have a compiler error which says that this exception is never thrown …
Run Code Online (Sandbox Code Playgroud)

java postgresql exception

4
推荐指数
2
解决办法
7347
查看次数

如何在Spring引导中为mongo db存储库进行自定义排序查询?

我想@Query在我的存储库中添加带有注释的查询.

这是查询:

`db.report.find({'company' : 'Random'}).sort( { 'reportDate' : -1} ).limit(1)`
Run Code Online (Sandbox Code Playgroud)

哪个是使用@Query注释实现自定义查询或使用MongoTemplate的最佳方法?

spring repository mongodb spring-boot

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

如何在springboot中连接到MongoDB?

我正在尝试使用mongoDB创建一个基础Spring应用程序,但我不知道如何连接到数据库.我试过这样的事情:

application.properties:

spring.data.mongodb.host=127.0.0.1
spring.data.mongodb.database=mongulet
spring.datasource.driver-class-name=mongodb.jdbc.MongoDriver
spring.data.mongodb.port=27017
Run Code Online (Sandbox Code Playgroud)

主要用途:

package com.example;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class RestSuperAdvancedApplication implements CommandLineRunner{

    @Autowired
    private CustomerRepository repository;

    public static void main(String[] args) {
        SpringApplication.run(RestSuperAdvancedApplication.class, args);
    }

    @Override
    public void run(String... strings) throws Exception {
        repository.deleteAll();

        repository.save(new Customer("Crisan", "Raoul"));
        repository.save(new Customer("Smith", "Martha"));
        repository.save(new Customer("Erie", "Jayne"));
        repository.save(new Customer("Robinson", "Crusoe"));

        System.out.println("Customers found : ");

        repository.findAll().forEach(System.out::println);

        System.out.println();

        System.out.println("Customer found by first name: (Erie)");
        System.out.println("----------------");
        System.out.println(repository.findOneByFirstName("Erie"));


    }
}
Run Code Online (Sandbox Code Playgroud)

客户类:

package com.example;

import javax.persistence.Id;

/**
 * …
Run Code Online (Sandbox Code Playgroud)

java repository mongodb spring-boot

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

如何启动将在java中按顺序运行的三个任务?

我正在尝试启动三个任务:第一个将读取一些电子邮件,在完成一项服务后,根据这些电子邮件生成一些图表将开始,最后这些图表将作为zip文件发送到电子邮件中.这些任务必须以这种精确的顺序运行:

dataReader - > graphGenerator - > emailSender.

我实现了这项服务,但我不明白为什么它不起作用.

@Component
public class WeeklyEmailService {
    @Autowired
    private EmailSender emailSender;
    @Autowired
    private GraphGenerator graphGenerator;
    @Autowired
    private DataReader dataReader;
    @Autowired
    private CompanyRepository companyRepository;
    @Autowired
    private EmailConfigurer emailConfigurer;
    @Value("${mail.username}")
    private String username;
    @Value("${mail.password}")
    private String password;

    public void sendWeeklyEmail() {
        emailConfigurer.setUsername(username);
        emailConfigurer.setPassword(password);
        if (emailConfigurer.configure() != null) {
            System.out.println("Connection successfully established with mail server!");
        }
        Task<Void> reader = new Task<Void>() {
            @Override
            protected Void call() throws Exception {
                dataReader.readWeeklyEmails();
                return null;
            }
        };

        Task<Void> generator …
Run Code Online (Sandbox Code Playgroud)

java concurrency multithreading

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

如何为UMASK设置tomcat 7环境变量?

我想将 tomcat 创建的日志的默认权限从 640 更改为 644,这需要更改 tomcat 的 umask。

tomcat用户的默认umask是027,我想将其设置为022。

我可以在 bin/setenv.sh 中为 tomcat7 设置 umask 属性的环境变量吗?我听说tomcat8有一个属性UMASK,但是版本7支持这个吗?

java tomcat

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

如何在春天将对象列表映射到具有休眠的表中?

我试图将用户列表映射到位置对象,但我得到映射异常.这是因为数据库无法识别List对象?或者为什么我会得到这个例外?

这是我的用户类:

@Entity
@Table(name = "users")
public class NewUser extends BaseEntity{
    private String login;
    private String fullName;

    private Location location;
    private Department department;
    private Role role;
    private Long days;
    private String team;
    private Long managerId;
    private String hiredDate;

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public Location getLocation() {
        return location;
    }

    @ManyToOne(targetEntity = Location.class) …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate

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

显示模式后整个窗口变得模糊 jQuery 为什么?

我想使用 jQuery 显示模式,但所有窗口都变得模糊,如下所示:

在此输入图像描述

这是js:

$(document).ready(function () {
    $('#addLocation').click(function () {
        $('#locationModal').modal('show');
    })
    $('#addDepartment').click(function () {
        $('#departmentModal').modal('show');
    })
    $('#addRole').click(function () {
        $('#roleModal').modal('show');
    })
});
Run Code Online (Sandbox Code Playgroud)

和html页面:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Pending Requests</title>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="css/settings.css"/>
    <link rel="stylesheet" type="text/css" href="css/navbar.css"/>
    <link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
</head>
<body>
<div class="icon-bar" style="float: left">
    <div class="employee"><a href="/"><i class="fa fa-home"></i></a></div>
    <div class="employee"><a href="summary.html"><i class="fa fa-list"></i></a><!--Summary--></div>
    <div class="employee"><a href="planDetails.html"><i class="fa fa-globe"></i></a><!--Plan details--></div>
    <div class="employee"><a href="newRequest.html"><i class="fa fa-building-o"></i></a><!--Company holidays--></div>
    <div …
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery bootstrap-modal

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