Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 春堂';t初始化我的@Configuration-classes_Java_Spring - Fatal编程技术网

Java 春堂';t初始化我的@Configuration-classes

Java 春堂';t初始化我的@Configuration-classes,java,spring,Java,Spring,我的Spring应用程序有点问题。 我用@Configuration注释类配置了不同的东西,当我在Netbeans中运行应用程序时,一切似乎都很好。但现在我想将我的应用程序构建为可执行的jar文件,它不再工作了。似乎找不到任何带注释的类 谢谢你的帮助 主要类别: @SpringBootApplication @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class, HibernateJpaAutoConfigurat

我的Spring应用程序有点问题。 我用@Configuration注释类配置了不同的东西,当我在Netbeans中运行应用程序时,一切似乎都很好。但现在我想将我的应用程序构建为可执行的jar文件,它不再工作了。似乎找不到任何带注释的类

谢谢你的帮助

主要类别:

@SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class StockServerApplication
{
    public static void main(String[] args) throws IOException
    {
        // Check if settings exists
        if(!AppSettings.settingsFileExists()){
            AppSettings.writeExampleSettingsFile();
            System.out.println("Settings-file not found. Example file has been written in the root-dir\nClosing...");
            System.exit(0);
        }

        AppSettings.initialize();

        if(!AppSettings.isValid()){
            System.exit(0);
        }

        SpringApplication app = new SpringApplication(StockServerApplication.class);

        Properties props = AppSettings.settingsToNativeProperties(AppSettings.applicationSettings);
        props.put("spring.thymeleaf.mode", "LEGACYHTML5");
        props.put("spring.thymeleaf.cache", "false");
        props.put("spring.jpa.database", "default");
        // Debug
       // props.put("debug", "true");
        app.setDefaultProperties(props);
        app.run(args);
    }

    @Autowired
    private AuthorizedUserRepository repo;

    @PostConstruct
    private void createAdmin(){

        AuthorizedUser user = repo.getByUsername("Admin");
        if(user == null){
            // Generate admin-user
            String possiblePasswordCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
            String generatedPassword = RandomStringUtils.random(10, possiblePasswordCharacters);
            user = new AuthorizedUser(null, null, "Admin", generatedPassword, null, AuthorizedUserRole.Admin);
            repo.save(user);
            System.out.println("\n\nCreated Admin-account with password: " + generatedPassword + "\n\n");
        }
    }
}
例如,这里是我的SecurityConfiguration类,它根本不需要初始化

@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter
{
    @Autowired
    private AuthenticationFilter filter;

    @Override
    protected void configure(HttpSecurity http) throws Exception
    {
        Settings.ServerSettings set = AppSettings.applicationSettings.getServerSettings();
        if(!set.isUseAuthentication())
            return;

        System.out.println("Initializing security-settings");

        http.csrf().disable().authorizeRequests()
                .antMatchers("/").permitAll()
                .antMatchers("/utils/**").permitAll()
                .antMatchers("/app/**").permitAll()
                .antMatchers("/authorize").permitAll()
                .antMatchers(HttpMethod.POST, "/users/add/*").hasAuthority(AuthorizedUserRole.Admin.toString())
                .antMatchers(HttpMethod.DELETE, "/users/delete/*").hasAuthority(AuthorizedUserRole.Admin.toString())
                .antMatchers(HttpMethod.GET, "/users/all/*").hasAuthority(AuthorizedUserRole.Admin.toString())
                .antMatchers(HttpMethod.PUT, "/users/changerole/*").hasAuthority(AuthorizedUserRole.Admin.toString())
                .anyRequest().authenticated()
                .and()
                .addFilterBefore(filter, UsernamePasswordAuthenticationFilter.class)
                .exceptionHandling()
                .authenticationEntryPoint(new AuthEntryPoint());
    }

    @Bean
    public FilterRegistrationBean authenticationFilterRegistrationBean(){
        FilterRegistrationBean regBean = new FilterRegistrationBean();
        regBean.setFilter(filter);
        regBean.setOrder(1);

        return regBean;
    }
}
这些类都不能在jar文件中工作。在IDE上,一切正常。 在过去的几天里,我试着搜索是否有人有同样的问题,但我什么也没找到

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>maja</groupId>
<artifactId>StockServer</artifactId>
<version>0.1</version>
<packaging>jar</packaging>

<name>StockServer</name>
<description>Stock handling server</description>

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

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <version>1.5.7.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
        <version>1.5.7.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>1.3.6.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <version>1.5.7.RELEASE</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <version>6.2.1.jre8</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>1.11.7.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.3.11.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot</artifactId>
        <version>1.5.7.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.6</version>
    </dependency>
    <!-- Spring Security -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
        <version>1.4.2.RELEASE</version>
    </dependency>

    <!-- JWT -->
    <dependency>
        <groupId>io.jsonwebtoken</groupId>
        <artifactId>jjwt</artifactId>
        <version>0.6.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.0</version>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.nekohtml</groupId>
        <artifactId>nekohtml</artifactId>
        <version>1.9.22</version>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.3.156</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.1.4.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.1.4.Final</version>
    </dependency>
</dependencies>

<build>
    <plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <executions>
            <execution>
                <goals>
                    <goal>repackage</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    </plugins>
</build>

4.0.0
马贾
股票服务器
0.1
罐子
股票服务器
库存处理服务器
UTF-8
UTF-8
1.8
org.springframework.boot
spring引导启动器数据jpa
1.5.7.1发布
org.springframework.boot
弹簧启动装置
1.5.7.1发布
org.springframework.boot
SpringBootStarterWeb
1.3.6.1发布
org.springframework.boot
弹簧起动试验
1.5.7.1发布
测试
com.microsoft.sqlserver
mssql jdbc
6.2.1.jre8
org.springframework.data
spring数据jpa
1.11.7.发布
org.springframework
弹簧网
4.3.11.1发布
org.springframework.boot
弹簧靴
1.5.7.1发布
org.apache.commons
commons-lang3
3.6
org.springframework.boot
弹簧启动安全
1.4.2.1发布
io.jsonwebtoken
jjwt
0.6.0
com.google.code.gson
格森
2.8.0
net.sourceforge.nekohtml
内科特米尔
1.9.22
com.h2数据库
氢
1.3.156
org.hibernate
休眠实体管理器
4.1.4.最终版本
org.hibernate.javax.persistence
hibernate-jpa-2.0-api
1.0.1.最终版本
org.hibernate
冬眠核心
4.1.4.最终版本
org.springframework.boot
springbootmaven插件
重新包装

请为projectI添加gradle/maven配置,我编辑了我的第一篇文章,我已经添加了pom.xml文件的副本。好的,谢谢。你是如何构建这个jar文件的?我不知道我是否理解你的意思,但我只是像往常一样在NetBeans中按build,它会为我构建jar文件。好的,我不使用NetBeans ide,但你应该尝试通过适当的maven任务来构建你的jar,比如在控制台中键入
mvn package
。对不起,我每天都在使用IntelliJ和Gradle,但我认为通过您的命令行和本文档,您可以解决您的问题:)请为projectI添加Gradle/maven配置编辑我的第一篇文章,我已经添加了pom.xml文件的副本。好的,谢谢。你是如何构建这个jar文件的?我不知道我是否理解你的意思,但我只是像往常一样在NetBeans中按build,它会为我构建jar文件。好的,我不使用NetBeans ide,但你应该尝试通过适当的maven任务来构建你的jar,比如在控制台中键入
mvn package
。很抱歉,我每天都使用IntelliJ和Gradle,但我认为通过您的命令行和本文档,您可以解决您的问题:)