I use spring-data-cassandra:3.3.1 and try to apply TimestampCodec. Documentation says that all codecs should be added through CodecRegistry, but says nothing about a way to access it.
I use config like this:
#Configuration
#EnableReactiveCassandraRepositories("com.example.repo")
public class CassandraConfig extends AbstractReactiveCassandraConfiguration
...but I don't understand how could I provide codecs.
Any ideas / examples?
You can override getSessionBuilderConfigurer inside your CassandraConfig class:
#Override
protected SessionBuilderConfigurer getSessionBuilderConfigurer() {
return (sessionBuilder) -> sessionBuilder.addTypeCodecs(ExtraTypeCodecs.LOCAL_TIMESTAMP_UTC);
}
Related
I have a JMX bean which is running on felix scr annotations (AEM 6.4.8, Java 8) and would like to refactor it so it uses OSGi annotations instead. Basically, it's pretty clear what to do, there is only one tiny little "=" that I guess needs to be escaped?
The old code looks like this:
#Component(immediate=true)
#Property(name="jmx.objectname", value={"com.mypackage.monitoring:type=HierarchyModificationListenerMbean"})
#Service
public class HierarchyModificationListenerMbeanImpl
extends AnnotatedStandardMBean
implements ListenerStats {
The refactored code would then be:
#Component(immediate=true, service = ListenerStats.class, property = {"jmx.objectname=com.mypackage.monitoring:type=HierarchyModificationListenerMbean"})
public class HierarchyModificationListenerMbeanImpl
extends AnnotatedStandardMBean
implements ListenerStats {
I am not sure how to deal with the ":type=" in this case.
Any ideas?
take a look at this page https://aem.redquark.org/2018/10/day-16-creating-jmx-mbeans-in-aem.html it looks like the property definition you have should do the trick
your code looks good to me. only thing is, do you have an interface HierarchyModificationListenerMbean? your implementation class should declare that it implements such interface
Example:
public interface MyMBean {
}
#Component(service = DynamicMBean.class, property = {
"jmx.objectname=com.yourproject.osgi:type=MyMBean"
})
public class MyMBeanImpl extends AnnotatedStandardMBean implements MyMBean {
public MyMBeanImpl() {
super(MyMBean.class)
}
}
If you are using Spring's SchedulerFactoryBean, it overrides the configured value from the properties file.
So if you tried to use JobStoreTx it is always overridden by the LocalDataSourceJobStore from spring
Code snippet below shows the part from the SchedulerFactoryBean. I have overcome it by using a customizer.
if (this.dataSource != null) {
mergedProps.setProperty(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName());
}
Using #QuartzDataSource should handle the problem as #nonzaprej mentioned in the comments
Here is also how I have overridden the value using a customizer
#Component
public class SchedulerFactoryCustomizer implements SchedulerFactoryBeanCustomizer {
using the customize method
#Override
public void customize(SchedulerFactoryBean schedulerFactoryBean) {
schedulerFactoryBean.setDataSource(dataSource);
}
I need something like:
#Named({"bean1", "bean2"})
#Service({"bean1", "bean2"})
Can someone help me?
Not directly, the way you have it. But it is possible by redefining an existing #Service (or #Component) as a #Bean with either a name or list of names, it is possible.
#Service("Service-A")
public class SampleService {
public String doSomething() { return "Foo"; }
}
#Configuration
public class SampleConfig {
#Bean(name = {"Service-B", "Service-C"})
public SampleService createMirroredService(#Autowired SampleService service) {
return service;
}
}
And now you have three instances of SampleService: Service-A (your #Service), Service-B, and Service-C. This works because you define one and just have the #Bean annotated method pass through the implementation, which has the effect of creating aliases. Make sure the configuration class is picked up in the scan and it should work fine.
Note: Although this works, and there are probably other solutions as well, I can't think of a case where I would need this. Perhaps if I'm integrating with a library that already exists that I can't change. But there doesn't strike me as a serious need for this, or else they would have made value on #Component an array.
Though I think #Todd answer is totally correct. It seems it has mislead some others to follow the idea. See Autowire Map with custom class and use aliases to get the correct object reference.
Therefore I would like to add an answer here to suggest one to use the below methodology instead.
#Configuration
public class SampleConfig {
#Bean(name = {"Service-A", "Service-B", "Service-C"})
public SampleService createMirroredService() {
return new SampleService();
}
}
This would be much cleaner than the above answer, though may not answer the question properly.
java.lang.RuntimeException: A Component requires the 'com.brightcove.player.event.Emits' annotation. If you wish to not listen or emit, create the corresponding annotation with an empty events list.
Has any one else face the same issue??
any help will be appreciable.
It sounds like you do not have the annotation
#Emits(events = {})
before your class declaration. If you show us the relevant fragment it might be obvious to someone what the problem is. A component that emits no events and listens for no events would look like,
/**
* Provides a Component object that is not very useful.
*/
#Emits(events = {})
#ListensFor(events = {})
public class NotVeryUsefulComponent extends AbstractComponent {
}
Please update the proguard with the following lines
-keep public class com.brightcove.player.** { public *;}
-keepclassmembers public class com.brightcove.player.** { public *;}
-keepclasseswithmembers public class com.brightcove.player.** { public *;}
-keep class com.google.android.exoplayer.** { *;}
If you are not using the exoplayer, omit the last line
Your proguard configuration is stripping out the annotations. As an example, please see the proguard-project.txt in our samples repo:
https://github.com/BrightcoveOS/android-player-samples/blob/master/proguard-project.txt
When using #before, it is only used in one class. How do I apply a global filter in playframework? So that one filter is used for all controller classes.
A simple solution is to extend a base controller for all of your controllers and have the #Before in the base controller.
The other option (and the better solution, as it is more flexible) is to use the #With annotation. The example on the play documentation is
Example:
public class Secure extends Controller {
#Before
static void checkAuthenticated() {
if(!session.containsKey("user")) {
unAuthorized();
}
}
}
And on another Controller:
#With(Secure.class)
public class Admin extends Application {
...
}
This means the Admin controller will process all the interceptors (#Before, #After, #Finally) contained within the Secure controller.
I did this very thing by handling incoming requests globally in the GlobalSettings class:
This describes the class:
http://www.playframework.org/documentation/2.0/JavaGlobal
This describes the method you'd want to override.
http://www.playframework.org/documentation/2.0/JavaInterceptors
Here's an example of how I used it in my own project (of course, this is a simplified version of what you're looking for):
#Override
public play.mvc.Action onRequest(play.mvc.Http.Request request, java.lang.reflect.Method method) {
if (request.path().startsWith("/secret/locked")) {
return new Action.Simple() {
#Override
public Result call(play.mvc.Http.Context ctx) throws Throwable {
return redirect(routes.Application.forbidden());
}
};
}
return super.onRequest(request, method);
}
You can simply use PlayPlugin for this issue. See here for more details.
It's not a good solution to extend a base controller for all of your controllers and have the #Before in the base controller.
You can extends the filter or essensialfilter .e.g.
class filter1 extends Filter {}
and apply filter1 to Global