I'm migrating to spring security 4.0.1 using java config instead of xml. When I autowire PasswordEncoder
, it gives me the following error:
HTTP Status 500 - org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.UsersComponent': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.crypto.password.PasswordEncoder com.car.component.impl.UsersComponentImpl.passwordEncoder; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.crypto.password.PasswordEncoder] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
我将发布我的所有配置文件.我不知道我哪里错了. …
我继承了一个与基于SOAP的Web服务进行通信的项目.虽然我已经做了很多年的Java并且已经做了很多工作,但我在这方面完全是菜鸟XML
.
我们有一个WSDL
服务文件,其中包含顶部的架构和下面的所有消息定义.在问题的核心,当我尝试通过我们的代码连接到服务时,我得到了可怕的无法编组类型" https.api_blah_com.services.v4.Product "作为元素,因为它缺少@XmlRootElement
注释]
我的项目已经有一个jaxws绑定文件:
<jaxws:bindings wsdlLocation="../resources/wsdl/BlahAPI.wsdl"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
<jaxws:bindings
node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='https:api.blah.com/services/v4']">
<jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xjc:generateElementProperty>true</xjc:generateElementProperty>
</jxb:globalBindings>`
</jaxws:bindings>
</jaxws:bindings>
Run Code Online (Sandbox Code Playgroud)
现在我已经读过,为了获得我生成的所有Java类@XmlRootElement
,我需要添加一个jaxb:globalBinding
简单模式.
我已经尝试添加到我的本地副本WSDL
:
<xs:annotation>
<xs:appinfo>
<jaxb:globalBindings>
<xjc:simple />
</jaxb:globalBindings>
</xs:appinfo>
</xs:annotation>
Run Code Online (Sandbox Code Playgroud)
但JAXB
编译器抱怨它不能遵守这个globalBindings自定义,因为它附加到错误的地方或与其他绑定不一致.
所以我尝试添加另一个绑定文件,仅用于jaxb,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings version="1.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxb:bindings schemaLocation="../resources/wsdl/blah.wsdl">
<jaxb:globalBindings>
<xjc:simple />
</jaxb:globalBindings>
</jaxb:bindings>
</jaxb:bindings>
Run Code Online (Sandbox Code Playgroud)
但后来我得到一个错误,blah.wsdl不是这个编译的一部分.
我非常接近这个服务......我只是无法通过这一件事,这对我来说都是新的,所以我不确定还有什么可以尝试的.
我可以将他们WSDL
分成一个XSD
和一个WSDL
?是否需要这项工作?
由于"只有空格返回方法可以注释@Scheduled
",当我使用@Bean
配置而不是xml配置时,如何使用Spring Batch和Spring Scheduler Task ?您可以在下面找到我的完整配置文件.当我从中触发main()
但只有一次时,它运行得很好.我想添加@Scheduled(fixedrate=9999)
以便以特定频率唤起相同的工作.据我所知,为了做到这一点,我被期望添加@Scheduled
step1方法,但我不能,因为它返回与void不同.
@Configuration
@EnableBatchProcessing
@EnableScheduling
public class BatchConfiguration {
private static final Logger log = LoggerFactory
.getLogger(BatchConfiguration.class);
@Bean
@StepScope
public FlatFileItemReader<Person> reader() {
log.info(new Date().toString());
FlatFileItemReader<Person> reader = new FlatFileItemReader<Person>();
reader.setResource(new ClassPathResource("test_person_json.js"));
reader.setLineMapper(new DefaultLineMapper<Person>() {
{
setLineTokenizer(new DelimitedLineTokenizer() {
{
setNames(new String[] {"firstName", "lastName" });
}
});
setFieldSetMapper(new BeanWrapperFieldSetMapper<Person>() {
{
setTargetType(Person.class);
}
});
}
});
return reader;
}
@Bean
public ItemProcessor<Person, Person> processor() {
return new …
Run Code Online (Sandbox Code Playgroud) @Component
public class SomeFactory implements ISomeFactory {
public someWatchFactory() {};
@Override
public boolean startWatch(MethodToWatch methodName, UUID uniqueID, Callable toRun) {
IPerformanceStopWatch mywatch = getStartWatch(methodName,uniqueID,toRun);
return mywatch.startWatchDeployTaskStatus();
}
@Lookup
private IPerformanceStopWatch getStartWatch(MethodToWatch methodName, String uniqueID, Callable toRun) {
IPerformanceStopWatch mywatch = getStartWatch(methodName,uniqueID,toRun);
return null; //stub implementation which will be replaced by the container
}
}
Run Code Online (Sandbox Code Playgroud)
我想测试工厂类,使用类似:
@InjectMock
ISomeFactory someFactory;
@Mock
IPerformanceStopWatch performanceWatch
Run Code Online (Sandbox Code Playgroud)
每当SomeFactory
类内的查找注释尝试获取实例时,它将使用模拟。
我该怎么做呢?
我想了解**@OneToMany**
有**@JoinTable**
这样之情况
我正在使用JPA 2.1,Hibernate 5.0.4和Oracle 11 XE.当我打电话userDao.save(user)
(下面的代码)我有
java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (HIBERNATE.USER2ORDER_PK) violated
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?有人可以帮我理解吗?
DDL:
DROP TABLE HIBERNATE.T_USER2ORDERS;
DROP TABLE HIBERNATE.T_ORDERS;
DROP TABLE HIBERNATE.T_USERS;
DROP SEQUENCE HIBERNATE.USERS_SEQ;
DROP SEQUENCE HIBERNATE.ORDERS_SEQ;
CREATE TABLE HIBERNATE.T_USERS (
ID NUMBER(15),
NAME VARCHAR2(100 CHAR),
CONSTRAINT USER_PK PRIMARY KEY (ID)
);
CREATE TABLE HIBERNATE.T_ORDERS (
ID NUMBER(15),
ORDER_DETAILS VARCHAR2(100 CHAR) NOT NULL,
CONSTRAINT UDETAILS_PK PRIMARY KEY (ID)
);
CREATE TABLE HIBERNATE.T_USER2ORDERS (
ID_USER NUMBER(15) NOT NULL,
ID_ORDER NUMBER(15) NOT NULL,
CONSTRAINT …
Run Code Online (Sandbox Code Playgroud) 也许我错过了一些东西,但我只想(在我的java程序中)从javax.persistence.Query
对象中获取查询字符串?该Query
对象本身似乎并不具备这样做的方法.另外我知道我们的经理不希望我们使用Spring框架的东西(例如使用他们的QueryUtils
类).
有没有办法简单地从javax.persistence.Query
对象中获取查询字符串(再次,在java程序中)?
我正在尝试使用JUnit和Mockito对我正在构建的Spring REST Web服务进行测试.我在尝试运行JUnit测试时遇到了一个错误,但无法找到有关该问题的任何信息.堆栈跟踪列出了错误行,.andDo(print())
因为我直接从spring.io教程获得该行http://spring.io/guides/tutorials/rest/3/
测试类代码:
public class TestSuite {
MockMvc mockMvc;
@Mock
RestController controller;
@Before
public void setup(){
MockitoAnnotations.initMocks(this);
this.mockMvc = standaloneSetup(controller)
.setMessageConverters(new MappingJackson2HttpMessageConverter()).build();
}
@Test
public void testREST() throws Exception {
when(controller.getThing(any(Integer.class))).thenReturn(TestFixture.getREST(1));
this.mockMvc.perform(get("/{number}", String.valueOf(number))
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isNotFound());
}}
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.isAsyncStarted()Z
at org.springframework.test.web.servlet.result.PrintingResultHandler.printAsyncResult(PrintingResultHandler.java:131)
at org.springframework.test.web.servlet.result.PrintingResultHandler.handle(PrintingResultHandler.java:80)
at org.springframework.test.web.servlet.MockMvc$1.andDo(MockMvc.java:155)
at org.company.test.TestSuite.testREST(TestSuite.java:53)`
Run Code Online (Sandbox Code Playgroud) 我已经安排了一个带有 annotation 的作业@Scheduled
,它应该使用 spring data jpa 处理数据并将其保存到数据库中。save
调用该方法没有任何异常,但没有插入数据库。在同一个带注释的方法中,我调用了findAll
工作正常并获取数据的方法。可能是什么原因?
@Repository
public interface PossibleOfferLinkRepository extends PagingAndSortingRepository<PossibleOfferLink, Long> {
}
@Configuration
@ComponentScan
@EnableAutoConfiguration
@Import({Scheduler.class})
@EntityScan(basePackages="model_package")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@EnableScheduling
@ConditionalOnProperty(value= "property_name")
public class Scheduler {
...
@Scheduled(fixedRate=100000)
public void scheduleCrawlerJob() throws MalformedURLException {
Iterable<PossibleOfferLink> links = repo.findAll();
PossibleOfferLink link = repo.save(new PossibleOfferLink(new URL("...")));
}
}
Run Code Online (Sandbox Code Playgroud)
马文
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.8.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency> …
Run Code Online (Sandbox Code Playgroud) 我试图返回一个从调用请求中的onResponse
方法获得的值,retrofit
有没有办法可以从覆盖的方法中获取该值?这是我的代码:
public JSONArray RequestGR(LatLng start, LatLng end)
{
final JSONArray jsonArray_GR;
EndpointInterface loginService = ServiceAuthGenerator.createService(EndpointInterface.class);
Call<GR> call = loginService.getroutedriver();
call.enqueue(new Callback<GR>() {
@Override
public void onResponse(Response<GR> response , Retrofit retrofit)
{
jsonArray_GR = response.body().getRoutes();
//i need to return this jsonArray_GR in my RequestGR method
}
@Override
public void onFailure(Throwable t) {
}
});
return jsonArray_GR;
}
Run Code Online (Sandbox Code Playgroud)
我无法得到价值,jsonArray_GR
因为能够在onResponse
方法中使用它我需要声明它最终,我不能给它一个值.
我找不到元素,这是我的代码:
public static void main(String[] args) {
BufferedReader br = getFileReader("reader.csv");
ArrayList<Monitoring> col = getCollection(br);
//sort the collection on 'beginTime'
for (Monitoring x : col)
System.out.println(x.toString());
BeginTimeComparator beginTime = new BeginTimeComparator();
Collections.sort(col,beginTime);
System.out.println("Begin time:");
for (Monitoring x : col)
System.out.println(x.toString());
Run Code Online (Sandbox Code Playgroud)
这是我遇到麻烦的部分,我不知道如何搜索使用endTime 2015-03-10获取对象.BTW这是一行cvs数据:
UnitId;BeginTime;EndTime;Type;Min;Max;Sum
Run Code Online (Sandbox Code Playgroud)
14100072; 2015-03-10 07:12:20; 2015-03-10 7:13:20; Gps/GpsAccuracyGyroBias; 0; 0; 0
//find the amount of elements that were sent on 'endTime' = 2015-03-10 (just the date)
EndTimeComparator endTime = new EndTimeComparator();
String findThis = "2015-03-10";
Collections.sort(col, endTime);
for(Monitoring x …
Run Code Online (Sandbox Code Playgroud) java ×9
spring ×6
hibernate ×2
jpa ×2
mockito ×2
arraylist ×1
collections ×1
cxf ×1
jax-ws ×1
jaxb ×1
json ×1
junit ×1
methods ×1
orm ×1
query-string ×1
retrofit ×1
spring-batch ×1
spring-boot ×1
spring-test ×1
unit-testing ×1
web-services ×1
wsdl ×1