我的 Spring Boot appl 中有这个配置类。v1.5.3. 发布
@Configuration
@Profile("dev && cub")
@PropertySource("file:///${user.home}/.cub/application-dev.properties")
public class CubDevelopmentConfig {
..
}
Run Code Online (Sandbox Code Playgroud)
这个属性在我的 application.properties 中定义
spring.profiles.active=dev, cub
Run Code Online (Sandbox Code Playgroud)
但未加载配置类
我也试过 @Profile("{dev && cub}")
我有一个基本的 SpringBoot 应用程序。使用 Spring Initializer、JPA、嵌入式 Tomcat、Thymeleaf 模板引擎,并打包为可执行 JAR 文件。我在扩展自的存储库中定义了此方法
CrudRepository<HotelPrice, Long>, PagingAndSortingRepository<HotelPrice, Long> {
Run Code Online (Sandbox Code Playgroud)
这是方法
List<HotelPrice> getByHotelAndUpdateDateGreaterThan (Hotel hotel, Date date, PageRequest pageRequest);
Run Code Online (Sandbox Code Playgroud)
和服务:
public List<HotelPrice> getMonthlyMinPriceDate(Hotel hotel) {
return hotelPriceRepository.getByHotelAndUpdateDateGreaterThan
(hotel, DateUtils.monthlyDate(), new PageRequest(1, 1,new Sort(Sort.Direction.DESC, "price")));
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行 Junit 测试时,我收到了这个错误:
java.util.NoSuchElementException
at java.util.ArrayList$Itr.next(ArrayList.java:860)
at java.util.Collections$UnmodifiableCollection$1.next(Collections.java:1042)
at org.springframework.data.jpa.repository.query.CriteriaQueryParameterBinder.bind(CriteriaQueryParameterBinder.java:65)
at org.springframework.data.jpa.repository.query.ParameterBinder.bind(ParameterBinder.java:101)
at org.springframework.data.jpa.repository.query.ParameterBinder.bindAndPrepare(ParameterBinder.java:161)
at org.springframework.data.jpa.repository.query.ParameterBinder.bindAndPrepare(ParameterBinder.java:152)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer.invokeBinding(PartTreeJpaQuery.java:236)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer.createQuery(PartTreeJpaQuery.java:157)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.doCreateQuery(PartTreeJpaQuery.java:86)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.createQuery(AbstractJpaQuery.java:190)
at org.springframework.data.jpa.repository.query.JpaQueryExecution$CollectionExecution.doExecute(JpaQueryExecution.java:123)
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:87)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:116)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:106)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:499)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:477)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:56)
at …Run Code Online (Sandbox Code Playgroud) 我想基于LocalDateTime对一个Collection进行分组,但我只想得到小时,而不是分钟,秒......
.collect(Collectors.groupingBy(cp -> getUpdateLocalDate())
public LocalDate getUpdateLocalDate() {
return getUpdateDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
}
Run Code Online (Sandbox Code Playgroud)
但是我还需要Date,比如:2018-10-12T09:00:00不仅仅是小时
阅读文档。的deploy:deploy-file(https://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html),似乎只有必需的参数是必需参数<file>, <repositoryId> and <url>但是当我运行,:
mvn deploy:deploy-file -Durl={url} -DrepositoryId={repoId} -Dfile=D:\Users\nunito\IdeaProjects\calzada\target\calzada.zip
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy-file (default-cli) on project oib-kw-guards-web: The artifact i
nformation is incomplete or not valid:
[ERROR] [0] 'groupId' is missing.
[ERROR] [1] 'artifactId' is missing.
[ERROR] [2] 'version' is missing.
Run Code Online (Sandbox Code Playgroud) 我有一个 twiiter 应用程序:
// 不记名令牌
// API 密钥
// API 密钥秘密
// 访问令牌:
// 访问令牌秘密:
和 Read, Write, and Direct Messages 权限
我使用 ConfigurationBuilder 类在 Java 中以编程方式配置 Twitter4J:
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("IX9qalH5azhSk61ZoFMiL83Jg") // API key
.setOAuthConsumerSecret("tidoT2GgVZE3B3txDb64tuinlv0wZHbKesX5bNIcjPWpxmcYcs") // API key secret
.setOAuthAccessToken("1345093646195010258-goY3W4oyqSltGFSUNPwJy8pSjSmfI5") // Access token:
.setOAuthAccessTokenSecret("ijkpYB8sacVcBdvKHOnh95Y3QRITzD3c4Uq8nUUMLTN8O"); //Access token secret:
TwitterFactory tf = new TwitterFactory(cb.build());
return tf.getInstance();
Run Code Online (Sandbox Code Playgroud)
但是当我尝试发布时出现此错误:
401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock …Run Code Online (Sandbox Code Playgroud) 我有这门课:
\n@Configuration\n@EnableWebSecurity\n@EnableGlobalMethodSecurity(prePostEnabled = true)\npublic class ApiWebSecurityConfig extends WebSecurityConfigurerAdapter {\n\n private static final String SALT = "fd&lkj\xc2\xa7isfs23#$1*(_)nof";\n\n private final JwtAuthenticationEntryPoint unauthorizedHandler;\n private final JwtTokenUtil jwtTokenUtil;\n private final UserSecurityService userSecurityService;\n\n @Value("${jwt.header}")\n private String tokenHeader;\n\n\n public ApiWebSecurityConfig(JwtAuthenticationEntryPoint unauthorizedHandler, JwtTokenUtil jwtTokenUtil,\n UserSecurityService userSecurityService) {\n this.unauthorizedHandler = unauthorizedHandler;\n this.jwtTokenUtil = jwtTokenUtil;\n this.userSecurityService = userSecurityService;\n }\n\n @Autowired\n public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {\n auth\n .userDetailsService(userSecurityService)\n .passwordEncoder(passwordEncoder());\n }\n\n @Bean\n public BCryptPasswordEncoder passwordEncoder() {\n return new BCryptPasswordEncoder(12, new SecureRandom(SALT.getBytes()));\n }\n\n @Bean\n @Override\n public AuthenticationManager authenticationManagerBean() throws …Run Code Online (Sandbox Code Playgroud) 我刚刚为WebLogic Server版本12.1.3.0.0创建了一个身份验证提供程序,(身份验证提供程序通过在许多可配置的JAAS LoginModule之上构建身份验证序列来遵守标准JAAS框架.)但是当我启动Wl I时有这个错误:
这里的步骤:
1)设置ENV
%WL_HOME%/server/bin/setWLSEnv.cmd
Run Code Online (Sandbox Code Playgroud)
2)生成MBean和stubs:
java -cp %WL_HOME%/server/lib/* -verbose -DcreateStubs="true" \
weblogic.management.commo.WebLogicMBeanMaker -MDF WSAuthentication.xml \
-files C:\Development\Workspaces\Eclipse\WLAuthenticationProvider\src
Run Code Online (Sandbox Code Playgroud)
3)使用生成的存根和MBI文件打包认证提供程序和登录模块.
java -DMJF=C:\Development\Workspaces\Eclipse\WLAuthenticationProvider\jar\WSAuthentication.jar \
-Dfiles=C:\Development\Workspaces\Eclipse\WLAuthenticationProvider\src weblogic.management.commo.WebLogicMBeanMaker
Run Code Online (Sandbox Code Playgroud)
4)在startWebLogic.cmd中添加-DUseSunHttpHandler = true
weblogic.security.service.SecurityServiceRuntimeException: [Security:090877]Service Common JAASAuthenticationService unavailable, see exception text: com.bea.common.engine.ServiceInitializationException: com.bea.common.engine.SecurityServiceRuntimeException: [Security:097533]SecurityProvider service class name for MyAuthentication is not specified.
at weblogic.security.service.PrincipalAuthenticator.initialize(PrincipalAuthenticator.java:155)
at weblogic.security.service.PrincipalAuthenticator.<init>(PrincipalAuthenticator.java:315)
at weblogic.security.service.CommonSecurityServiceManagerDelegateImpl.doATN(CommonSecurityServiceManagerDelegateImpl.java:731)
at weblogic.security.service.CommonSecurityServiceManagerDelegateImpl.postInitializeRealm(CommonSecurityServiceManagerDelegateImpl.java:515)
at weblogic.security.service.CommonSecurityServiceManagerDelegateImpl.postLoadRealm(CommonSecurityServiceManagerDelegateImpl.java:861)
at weblogic.security.service.CommonSecurityServiceManagerDelegateImpl.postInitializeRealms(CommonSecurityServiceManagerDelegateImpl.java:927)
at weblogic.security.service.CommonSecurityServiceManagerDelegateImpl.postInitialize(CommonSecurityServiceManagerDelegateImpl.java:1109)
at weblogic.security.service.SecurityServiceManager.postInitialize(SecurityServiceManager.java:943)
at weblogic.security.SecurityService.start(SecurityService.java:159)
at weblogic.server.AbstractServerService.postConstruct(AbstractServerService.java:78)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.glassfish.hk2.utilities.reflection.ReflectionHelper.invoke(ReflectionHelper.java:1017)
at org.jvnet.hk2.internal.ClazzCreator.postConstructMe(ClazzCreator.java:388)
at …Run Code Online (Sandbox Code Playgroud) 我使用 Spring Initializer、嵌入式 Tomcat、Thymeleaf 模板引擎生成了一个 Spring Boot Web 应用程序,并将其打包为可执行 JAR 文件。
使用的技术:
Spring Boot 1.4.2.RELEASE、Spring 4.3.4.RELEASE、Thymeleaf 2.1.5.RELEASE、Tomcat Embed 8.5.6、Maven 3、Java 8
这是我的安全配置类:
@Configuration
@EnableWebSecurity
@PropertySource("classpath:/com/tdk/iot/config/app-${APP-KEY}.properties")
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Value("${securityConfig.formLogin.loginPage}")
private String loginPage;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin()
.loginPage(loginPage)
.permitAll()
.loginProcessingUrl("/login")
.failureUrl("/login.html?error=true")
.defaultSuccessUrl("/books/list")
.and()
.exceptionHandling()
.accessDeniedPage("/denied")
.and()
.authorizeRequests()
.antMatchers("/mockup/**").permitAll()
.antMatchers("/books/**").permitAll()
.antMatchers("/welcome/**").authenticated()
.and()
.logout()
.permitAll()
.logoutSuccessUrl("/index.html");
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.passwordEncoder(new StandardPasswordEncoder())
.withUser("test1").password("test1").roles("ADMIN").and()
.withUser("test2").password("test2").roles("USER").and()
.withUser("test3").password("test3").roles("SUPERADMIN");
}
@Bean …Run Code Online (Sandbox Code Playgroud) authentication spring spring-mvc spring-security spring-boot
我使用Spring Initializer,嵌入式Tomcat,Thymeleaf模板引擎和包作为可执行JAR文件生成了一个Spring Boot Web应用程序.
使用的技术:
Spring Boot 1.4.2.RELEASE,Spring 4.3.4.RELEASE,Thymeleaf 2.1.5.RELEASE,Tomcat Embed 8.5.6,Maven 3,Java 8
这是我在启动数据库时调用的bean
@SpringBootApplication
@EnableAutoConfiguration
@Import({SecurityConfig.class})
public class BookApplication {
public static void main(String[] args) {
SpringApplication.run(BookApplication.class, args);
}
}
@Configuration
public class PersistenceConfig {
...
/**
* Creates an in-memory "books" database populated
* with test data for fast testing
*/
@Bean
public DataSource dataSource(){
return
(new EmbeddedDatabaseBuilder())
.addScript("classpath:db/H2.schema.sql")
.addScript("classpath:db/H2.data.sql")
.build();
}
Run Code Online (Sandbox Code Playgroud)
当我执行此插入时
CREATE TABLE IF NOT EXISTS t_time_lapse (
id bigint PRIMARY KEY,
name varchar(50) NOT …Run Code Online (Sandbox Code Playgroud) 我有一个基本的 SpringBoot 2.0.4.RELEASE 应用程序。使用 Spring Initializer、JPA、嵌入式 Tomcat、Thymeleaf 模板引擎,并打包为可执行 JAR 文件。
我有一个具有角色的用户对象:
@Entity
@Table(name="t_user")
public class User implements Serializable, UserDetails {
@ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
@JoinTable(
name="t_user_role",
joinColumns=@JoinColumn(name="user_id", referencedColumnName="id"),
inverseJoinColumns=@JoinColumn(name="role_id", referencedColumnName="id"))
private Set<Role> roles = new HashSet<>();
..
}
Run Code Online (Sandbox Code Playgroud)
当我启动应用程序时。我创建了所有角色:
roleService.save(new Role(RolesEnum.USER.getRoleName()));
roleService.save(new Role(RolesEnum.ADMIN.getRoleName()));
Run Code Online (Sandbox Code Playgroud)
然后我创建一个具有 USER 角色的用户:
User user1 = new User();
Role role = roleService.findByName(RolesEnum.USER.getRoleName());
user.getRoles().add(role);
userService.save(user);
Run Code Online (Sandbox Code Playgroud)
但是当我创建另一个具有相同角色的用户时:
User user2 = new User();
Role role = roleService.findByName(RolesEnum.USER.getRoleName());
user2.getRoles().add(role);
user2Service.save(user);
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
Multiple representations of the same entity [com.tdk.backend.persistence.domain.backend.Role#1] are …Run Code Online (Sandbox Code Playgroud) hibernate spring-mvc spring-data spring-data-jpa spring-boot
spring-boot ×6
java ×4
spring-mvc ×4
spring ×3
hibernate ×2
spring-data ×2
collections ×1
h2 ×1
java-8 ×1
java-stream ×1
jpa ×1
jpanel ×1
jwt ×1
maven ×1
mysql ×1
oauth ×1
rest ×1
security ×1
twitter4j ×1
weblogic12c ×1